{"id":406,"date":"2015-02-24T00:00:00","date_gmt":"2015-02-24T00:00:00","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2015\/02\/24\/going-meta-with-meta-runners-in-teamcity\/"},"modified":"2018-09-25T07:37:38","modified_gmt":"2018-09-25T07:37:38","slug":"going-meta-with-meta-runners-in-teamcity","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/going-meta-with-meta-runners-in-teamcity\/","title":{"rendered":"Going meta with Meta-Runners in TeamCity"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3508 size-full\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2015\/02\/teamcity-meta-with-meta-run-1.png\" alt=\"teamcity-meta-with-meta-runners\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/teamcity-meta-with-meta-run-1.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/02\/teamcity-meta-with-meta-run-1-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/h1>\n<h1>Going meta with Meta-Runners in TeamCity<\/h1>\n<p><strong>Official Reference &#8211;\u00a0<\/strong><a href=\"https:\/\/confluence.jetbrains.com\/display\/TCD9\/Working+with+Meta-Runner\" target=\"_blank\" rel=\"noopener\">https:\/\/confluence.jetbrains.com\/display\/TCD9\/Working+with+Meta-Runner<\/a><\/p>\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 decoding=\"async\" src=\"http:\/\/techbus.safaribooksonline.com\/getfile?item=ZWc1Ni9zOGFkLzE4Lzltc2ljdHAxOThzOTk0cjdhaWMwajFnb3BlcjgxLzlwc2F0L2c4Xy4wX3RzNWg-\" alt=\"Going meta with Meta-Runners\" \/><\/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 decoding=\"async\" src=\"http:\/\/techbus.safaribooksonline.com\/getfile?item=ZWc1Ni9zOGFkLzE4Lzltc2ljdHAxOThzOTk0cjdhaWMwajFnb3BlcjgxLzlwc2F0L2c5Xy4wX3RzNWg-\" alt=\"Going meta with Meta-Runners\" \/><\/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 decoding=\"async\" src=\"http:\/\/techbus.safaribooksonline.com\/getfile?item=ZWc1Ni9zOGFkLzE4Lzltc2ljdHAxOThzOTk0cjdhaWMxajFnb3BlcjgxLzlwc2F0L2cwXy4wX3RzNWg-\" alt=\"Using Meta-Runners\" \/><\/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 decoding=\"async\" src=\"http:\/\/techbus.safaribooksonline.com\/getfile?item=ZWc1Ni9zOGFkLzE4Lzltc2ljdHAxOThzOTk0cjdhaWMxajFnb3BlcjgxLzlwc2F0L2cxXy4wX3RzNWg-\" alt=\"Using Meta-Runners\" \/><\/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 i<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Going meta with Meta-Runners in TeamCity Official Reference &#8211;\u00a0https:\/\/confluence.jetbrains.com\/display\/TCD9\/Working+with+Meta-Runner 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&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":3508,"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":[449],"tags":[1753,101,1751,1752,1754,144,1755],"class_list":["post-406","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-teamcity-build-management-tools","tag-build-configuration","tag-continuous-integration","tag-meta","tag-meta-runners","tag-meta-runners-in-teamcity","tag-teamcity","tag-working-with-meta-runner"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/406","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=406"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/406\/revisions"}],"predecessor-version":[{"id":3509,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/406\/revisions\/3509"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/3508"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}