{"id":405,"date":"2015-02-24T00:00:00","date_gmt":"2015-02-24T00:00:00","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2015\/02\/24\/build-configuration-templates-in-teamcity\/"},"modified":"2017-12-21T10:33:27","modified_gmt":"2017-12-21T10:33:27","slug":"build-configuration-templates-in-teamcity","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/build-configuration-templates-in-teamcity\/","title":{"rendered":"Build Configuration Templates in Teamcity | Teamcity Guide"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3513 aligncenter\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2015\/02\/build-configuration-templat.png\" alt=\"build-configuration-templates-in-teamcity\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/build-configuration-templat.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/build-configuration-templat-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/h1>\n<h1>Going meta with Meta-Runners in TeamCity<\/h1>\n<\/div>\n<\/div>\n<\/div>\n<p><a name=\"We have\"><\/a>We have seen that build runners can be very handy. Even though most build runners can be replaced with an equivalent command using the command-line runner, build runners come with the convenience of easily setting up build steps, along with the necessary agent requirements and parameters.<\/p>\n<p>Meta-Runners<a id=\"id772\"><\/a><a name=\"to create\"><\/a> provide a straightforward way to create custom build runners. Meta-Runners can be thought of as a way to avoid duplications in build steps across build configurations.<\/p>\n<div title=\"Note\">\n<div>\n<h3><a id=\"note93\"><\/a>Note<\/h3>\n<p><a name=\"create and\"><\/a>While templates can be used to create and maintain build configurations that are very similar, Meta-Runners can be used across build configurations that perform the same build steps. Moreover, a build configuration can only be based on one template, but it can make use of multiple Meta-Runners.<\/p>\n<\/div>\n<\/div>\n<p>In <a title=\"Chapter\u00a03.\u00a0Getting Your CI Up and Running\" href=\"http:\/\/techbus.safaribooksonline.com\/9781849699518\/ch03_html\" data-ajax=\"1\" target=\"_blank\" rel=\"noopener\">Chapter 3<\/a>, <em>Getting Your CI Up and Running<\/em>, we created the deploy-to-test<a name=\"application to\"><\/a> build configuration that deploys the Django application to Heroku. Using this build configuration as an example, we can see how we can extract a Meta-Runner Deploy To Heroku<a name=\"that wants\"><\/a> that can be used by any build configuration that wants to deploy to Heroku.<\/p>\n<p>Recall that the deploy-to-test build configuration<a id=\"id773\"><\/a> had a simple command-line runner that executed the following commands:<\/p>\n<div>\n<pre><strong>git remote add heroku git@heroku.com:django-ci-example.git<\/strong>  <strong>git push heroku master<\/strong><\/pre>\n<\/div>\n<p>To create a generic Meta-Runner<a id=\"id774\"><\/a><a name=\"to push\"><\/a> out of this, we need to provide a way to push to any remote, rather than just git@heroku.com:django-ci-example.git.<\/p>\n<div title=\"Note\">\n<div>\n<h3><a id=\"note94\"><\/a>Note<\/h3>\n<p>Deploying to Heroku using remotes needs the ssh<a name=\"example used\"><\/a> keys to be set up on the agent. The example used here just illustrates Meta-Runners and may not be ideal for production use.<\/p>\n<p><a name=\"in\"><\/a>As mentioned in <a title=\"Chapter\u00a06.\u00a0TeamCity for Ruby Projects\" href=\"http:\/\/techbus.safaribooksonline.com\/9781849699518\/ch06_html\" data-ajax=\"1\" target=\"_blank\" rel=\"noopener\">Chapter 6<\/a>, <em><a name=\"for Ruby\"><\/a>TeamCity for Ruby Projects<\/em>, we can use<a id=\"id775\"><\/a> a gem such <a id=\"id776\"><\/a>as heroku-headless (<a href=\"https:\/\/github.com\/moredip\/heroku-headless\" target=\"_new\" rel=\"noopener\">https:\/\/github.com\/moredip\/heroku-headless<\/a>).<\/p>\n<\/div>\n<\/div>\n<p><a name=\"extracting the\"><\/a>As expected, we will do this by extracting the remote out into a build parameter. The command-line runner will have the following as the <strong><a name=\"Custom Script\"><\/a>Custom Script<\/strong> to be run:<\/p>\n<div>\n<pre><strong>git remote add heroku %heroku.remote%<\/strong>  <strong>git push heroku master<\/strong><\/pre>\n<\/div>\n<p><a name=\"value for\"><\/a>We will provide the value for the %heroku.remote% parameter in the <strong>Build Parameters<\/strong> section of the build configuration.<\/p>\n<p><a name=\"a Meta\"><\/a>Now we are ready to create a Meta-Runner from this build configuration. This can be done by clicking on the <strong>Extract Meta-Runner<\/strong><a name=\"the build\"><\/a> button in the right-hand side bar of the build configuration settings page. This brings up the <strong>Extract Meta-Runner<\/strong> dialog, which is shown in the following screenshot:<\/p>\n<div><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-401\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity1.jpg\" alt=\"Going meta with Meta-Runners\" width=\"683\" height=\"405\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity1.jpg 683w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity1-300x178.jpg 300w\" sizes=\"auto, (max-width: 683px) 100vw, 683px\" \/><\/div>\n<p>In the dialog, we<a id=\"id777\"><\/a><a name=\"name that\"><\/a> give a name to the Meta-Runner. This is the name that will appear in the <strong>Runner Type<\/strong><a name=\"build configuration\"><\/a> field when configuring a build step for a build configuration.<\/p>\n<p>Click on <strong>Extract<\/strong><a name=\"see it\"><\/a> to create the Meta-Runner. Once the Meta-Runner is created, we can see it listed in the <strong>Meta-Runners<\/strong><a name=\"the project\"><\/a> tab on the project administration page. We can also edit the Meta-Runner to fine-tune it as desired.<\/p>\n<div title=\"Note\">\n<div>\n<h3><a id=\"tip77\"><\/a>Tip<\/h3>\n<p><a name=\"is essentially\"><\/a>A Meta-Runner is essentially an XML configuration (much like most TeamCity configurations) that can be edited directly from the web interface.<\/p>\n<\/div>\n<\/div>\n<p><a name=\"page of\"><\/a>The following screenshot shows the edit page of the Deploy To Heroku<a name=\"that we\"><\/a> Meta-Runner that we just created:<\/p>\n<div><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-402\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity2.jpg\" alt=\"Going meta with Meta-Runners\" width=\"806\" height=\"564\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity2.jpg 806w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity2-300x210.jpg 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity2-768x537.jpg 768w\" sizes=\"auto, (max-width: 806px) 100vw, 806px\" \/><\/div>\n<p>The <a id=\"id778\"><\/a><a name=\"and steps\"><\/a>Meta-Runner extracts all the parameters and steps defined in the build configuration. We can edit the Meta-Runner to have only the necessary parameters and steps.<\/p>\n<div title=\"Using Meta-Runners\">\n<div>\n<div>\n<div>\n<h2><a id=\"ch10lvl2sec93\"><\/a>Using Meta-Runners<\/h2>\n<\/div>\n<\/div>\n<\/div>\n<p>We can <a id=\"id779\"><\/a><a name=\"pretty much\"><\/a>now use the Meta-Runner that we created pretty much like a normal build runner. We will remove the existing build step in the deploy-to-test<a name=\"and add\"><\/a> build configuration (from which we extracted the Meta-Runner) and add a Deploy To Heroku Meta-Runner-based build step.<\/p>\n<div title=\"Note\">\n<div>\n<h3><a id=\"tip78\"><\/a>Tip<\/h3>\n<p><a name=\"want to\"><\/a>We can also disable build steps if we don&#8217;t want to remove them while experimenting.<\/p>\n<\/div>\n<\/div>\n<p>In the <strong>New Build Step<\/strong> page, for the <strong>Runner type<\/strong> field, the newly created <strong>Deploy To Heroku<\/strong> Meta-Runner is available, as shown in the following screenshot:<\/p>\n<div><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-403\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity3.jpg\" alt=\"Using Meta-Runners\" width=\"480\" height=\"381\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity3.jpg 480w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity3-300x238.jpg 300w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/div>\n<p>Once we <a id=\"id780\"><\/a>choose the Deploy To Heroku Meta-Runner, we can see that the heroku.remote<a name=\"Since we\"><\/a> parameter is one of the fields to be configured. Since we created the Meta-Runner with the heroku.remote parameter with the value git@heroku.com:django-ci-example.git, that remote is available by default. The Deploy To Heroku runner configuration page is shown in the following screenshot:<\/p>\n<div><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-404\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity4.jpg\" alt=\"Using Meta-Runners\" width=\"692\" height=\"342\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity4.jpg 692w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/Going-meta-with-Meta-Runners-in-teamcity4-300x148.jpg 300w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/div>\n<div title=\"Note\">\n<div>\n<h3><a id=\"tip79\"><\/a>Tip<\/h3>\n<p><a name=\"parameters in\"><\/a>It is possible to remove the value for parameters in the Meta-Runner XML so that no default values are present for the fields.<\/p>\n<\/div>\n<\/div>\n<p>We can<a id=\"id781\"><\/a> click on <strong>Save<\/strong><a name=\"the build\"><\/a> to add the build step. The new build step, based on the Deploy To Heroku<a name=\"function in\"><\/a> Meta-Runner, will function in the same way as the previous build step based on the command-line runner.<\/p>\n<div title=\"Note\">\n<div>\n<h3><a id=\"note95\"><\/a>Note<\/h3>\n<p><a name=\"apparent when\"><\/a>Of course, the value of Meta-Runners becomes more apparent when we create them out of multiple build steps. The same set of steps that may be repeated across multiple configurations can be extracted into Meta-Runners.<\/p>\n<p><span style=\"font-weight: 600; color: #555555; font-family: 'Open Sans', Arial, sans-serif; font-size: 14px; line-height: 28px;\">Reference Book<\/span><span style=\"color: #555555; font-family: 'Open Sans', Arial, sans-serif; font-size: 14px; line-height: 28px;\">\u00a0&#8211; Learning Continuous Integration with TeamCity by Learning Continuous Integration with TeamCity<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Going meta with Meta-Runners in TeamCity We have seen that build runners can be very handy. Even though most build runners can be replaced with an equivalent command using the command-line runner, build runners come with the convenience of easily setting up build steps, along with the necessary agent requirements and parameters. Meta-Runners provide a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":3513,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[91,1753,1766,1767,679,282,144,1769,1768,315],"class_list":["post-405","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorised","tag-build","tag-build-configuration","tag-build-configuration-templates","tag-build-configuration-templates-in-teamcity","tag-build-management","tag-configuration","tag-teamcity","tag-teamcity-guide","tag-teamcity-tutorial","tag-templates"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=405"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/405\/revisions"}],"predecessor-version":[{"id":3516,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/405\/revisions\/3516"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/3513"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}