{"id":40612,"date":"2016-09-28T11:34:10","date_gmt":"2016-09-28T06:04:10","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=40612"},"modified":"2016-10-04T21:38:39","modified_gmt":"2016-10-04T16:08:39","slug":"jenkins-parameterized-publishing","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/jenkins-parameterized-publishing\/","title":{"rendered":"Jenkins Parameterized Publishing"},"content":{"rendered":"<p style=\"text-align: justify\"><span style=\"font-weight: 400\">The popular <a title=\"continuous integration DevOps services\" href=\"http:\/\/www.tothenew.com\/devops-chef-puppet-docker\">Continuous Integration<\/a> tool \u2018<strong>Jenkins<\/strong>\u2019 comes with multiple plugins which increase\u00a0the functionality of Jenkins many folds and helps DevOps achieve automation in many ways. One of the most important plugins it support is <\/span><a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Publish+Over+SSH+Plugin\"><span style=\"font-weight: 400\">Publish Over SSH<\/span><\/a><span style=\"font-weight: 400\">, which helps to transfer artifacts to any SSH server and\/or execute commands over SSH session. One of the important features of this plugin is to support Parameterized publishing. <\/span><\/p>\n<p style=\"text-align: justify\"><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40717\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/jenkins_image.png\" alt=\"jenkins_image\" width=\"676\" height=\"411\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/jenkins_image.png 676w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/jenkins_image-300x182.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/jenkins_image-624x379.png 624w\" sizes=\"(max-width: 676px) 100vw, 676px\" \/><\/strong><\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">This post will tell you how to use parameterized publishing with Jenkins. There are scenarios when we want to use Publish plugin only for some set of servers and want to skip for others. Suppose there are two type of servers (say App &amp; API) in different environments where we usually deploy and do some changes through SSH, or using Publish Over SSH Plugin. <\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">Now, there can be multiple situations where we want to deploy few artifacts on all the app servers irrespective of the environment or deploy artifacts on complete production environment irrespective of the type of server.<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">The first thing you will do is to add those servers on the Jenkins &#8211; \u2018<strong>Configure Systems<\/strong>.&#8217; <\/span><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40727\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_app.png\" alt=\"staging_app\" width=\"1358\" height=\"130\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_app.png 1358w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_app-300x28.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_app-1024x98.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_app-624x59.png 624w\" sizes=\"(max-width: 1358px) 100vw, 1358px\" \/><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40724\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_api.png\" alt=\"staging_api\" width=\"1358\" height=\"130\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_api.png 1358w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_api-300x28.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_api-1024x98.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_api-624x59.png 624w\" sizes=\"(max-width: 1358px) 100vw, 1358px\" \/><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40726\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_app.png\" alt=\"production_app\" width=\"1360\" height=\"134\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_app.png 1360w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_app-300x29.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_app-1024x100.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_app-624x61.png 624w\" sizes=\"(max-width: 1360px) 100vw, 1360px\" \/><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40725\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_api.png\" alt=\"production_api\" width=\"1362\" height=\"136\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_api.png 1362w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_api-300x29.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_api-1024x102.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_api-624x62.png 624w\" sizes=\"(max-width: 1362px) 100vw, 1362px\" \/><\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">You create a parameterized Job where you use a String Parameter to enter the expression which matches it against the LABEL of the servers and execute accordingly:<\/span><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40723\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/parameterized_publishing.png\" alt=\"parameterized_publishing\" width=\"1932\" height=\"434\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/parameterized_publishing.png 1932w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/parameterized_publishing-300x67.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/parameterized_publishing-1024x230.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/parameterized_publishing-624x140.png 624w\" sizes=\"(max-width: 1932px) 100vw, 1932px\" \/><\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">Next thing is to configure the Job using Publish Over SSH Plugin. You just add a Build step: <\/span><b>Send Files or execute commands over SSH<\/b><span style=\"font-weight: 400\">. Here you select the server where you want to execute this section:<\/span><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40719\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_app_build.png\" alt=\"staging_app_build\" width=\"1350\" height=\"452\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_app_build.png 1350w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_app_build-300x100.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_app_build-1024x342.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_app_build-624x208.png 624w\" sizes=\"(max-width: 1350px) 100vw, 1350px\" \/><\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">The server selected here is cw-staging-app. You must add a LABEL for this server. You can choose any label here. Just for understanding, let us use the same name. It must be noted that the expression on the aforementioned Parameter will match this label to decide which one to use and which one to skip.<\/span><\/p>\n<p style=\"text-align: justify\"><strong> <span style=\"font-weight: 400\">Similarly, add other servers for the same action by using \u2018Add Server\u2019 button just at the below of the build step. So, at last, you will have other three servers added as well like below:<\/span><\/strong><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40722\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_api_build.png\" alt=\"staging_api_build\" width=\"1360\" height=\"442\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_api_build.png 1360w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_api_build-300x97.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_api_build-1024x332.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/staging_api_build-624x202.png 624w\" sizes=\"(max-width: 1360px) 100vw, 1360px\" \/><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40721\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_app_build.png\" alt=\"production_app_build\" width=\"1352\" height=\"458\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_app_build.png 1352w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_app_build-300x101.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_app_build-1024x346.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_app_build-624x211.png 624w\" sizes=\"(max-width: 1352px) 100vw, 1352px\" \/><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40720\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_api_builld.png\" alt=\"production_api_builld\" width=\"1350\" height=\"448\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_api_builld.png 1350w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_api_builld-300x99.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_api_builld-1024x339.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/production_api_builld-624x207.png 624w\" sizes=\"(max-width: 1350px) 100vw, 1350px\" \/><\/p>\n<p style=\"text-align: justify\"><strong>\u00a0<\/strong>Now, the last step is to add Parameterized Publishing Parameter Name for this build step. You will find that just below the \u2018Add Server\u2019 button and above the \u2018Add Build Step\u2019 drop down. Add the Parameter name same as what you have used in Parameterized Job. This means that anything mentioned on DEPLOYMENT parameter will be matched against the LABELs of the servers for the section.<\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40718\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/parameterzied_publishing_parameter_name.png\" alt=\"parameterzied_publishing_parameter_name\" width=\"1744\" height=\"578\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/parameterzied_publishing_parameter_name.png 1744w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/parameterzied_publishing_parameter_name-300x99.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/parameterzied_publishing_parameter_name-1024x339.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/parameterzied_publishing_parameter_name-624x206.png 624w\" sizes=\"(max-width: 1744px) 100vw, 1744px\" \/><\/p>\n<p style=\"text-align: justify\">Now, it\u2019s time to run the Job!<\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">Select the regex patterns as per your needs. This will support all Java Regex <\/span><a href=\"http:\/\/docs.oracle.com\/javase\/1.5.0\/docs\/api\/index.html?java\/util\/regex\/Pattern.html\"><span style=\"font-weight: 400\">patterns<\/span><\/a><span style=\"font-weight: 400\">. You can also use <\/span><a href=\"http:\/\/regexr.com\/\"><span style=\"font-weight: 400\">Regex creator<\/span><\/a><span style=\"font-weight: 400\">. <\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">In case the regex pattern is wrong or does not matches it will give skip all the server sections:<\/span><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40730\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_nothingMatches.png\" alt=\"regex_nothingMatches\" width=\"1716\" height=\"400\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_nothingMatches.png 1716w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_nothingMatches-300x69.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_nothingMatches-1024x238.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_nothingMatches-624x145.png 624w\" sizes=\"(max-width: 1716px) 100vw, 1716px\" \/><\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">In case regex pattern matches for all the <\/span><b>app<\/b><span style=\"font-weight: 400\"> servers irrespective of the environment name:<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">For example: <\/span><b>.*-app$<\/b><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40731\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_allAPP.png\" alt=\"regex_allAPP\" width=\"1622\" height=\"808\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_allAPP.png 1622w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_allAPP-300x149.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_allAPP-1024x510.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_allAPP-624x310.png 624w\" sizes=\"(max-width: 1622px) 100vw, 1622px\" \/><\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">In case regex pattern matches for all the <\/span><b>prod<\/b><span style=\"font-weight: 400\"> servers irrespective of the type of server:<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\">For example: <\/span><b>.*-prod.*-.*<\/b><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-40729\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_allProd.png\" alt=\"regex_allProd\" width=\"1618\" height=\"978\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_allProd.png 1618w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_allProd-300x181.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_allProd-1024x618.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/regex_allProd-624x377.png 624w\" sizes=\"(max-width: 1618px) 100vw, 1618px\" \/><\/p>\n<p style=\"text-align: justify\"><strong><span style=\"font-weight: 400\">If a Label is missing on a server it will default to the empty string. You can use the same label multiple times, e.g. UAT for a web server and again for the database server. Labels can also use the standard Jenkins variables e.g. $NODE_NAME.<\/span><\/strong><\/p>\n<p class=\"p1\">So, when you would like to have a single Jenkins job that accepts a parameter to build for different environments i.e. Dev, Stage, Prod etc you can definitely consider Parameterised Publishing on Jenkins.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The popular Continuous Integration tool \u2018Jenkins\u2019 comes with multiple plugins which increase\u00a0the functionality of Jenkins many folds and helps DevOps achieve automation in many ways. One of the most important plugins it support is Publish Over SSH, which helps to transfer artifacts to any SSH server and\/or execute commands over SSH session. One of the [&hellip;]<\/p>\n","protected":false},"author":181,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":29},"categories":[2348,1],"tags":[4016,2845,4039,4038,4036,4037],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40612"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/181"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=40612"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40612\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=40612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=40612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=40612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}