{"id":1751,"date":"2020-03-23T23:31:15","date_gmt":"2020-03-23T20:31:15","guid":{"rendered":"https:\/\/artem.services\/?p=1748"},"modified":"2020-03-23T23:34:26","modified_gmt":"2020-03-23T20:34:26","slug":"1751","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1751&lang=en","title":{"rendered":"Jenkins &#8212; Checking if a string value is set to a parameter"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-819\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo.png\" alt=\"\" width=\"1280\" height=\"412\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo.png 1280w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-300x97.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-768x247.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-1024x330.png 1024w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-954x307.png 954w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Check if the value of the variable &quot;<strong>GIT_COMMIT_ID<\/strong>&quot; is set, if so, then do a checkout by the hash of the commit, if not, then do a checkout by the name of the branch. The variable &quot;<strong>GIT_BRANCH_NAME<\/strong>&quot; is taken from the <strong>Active Choice<\/strong> parameter.<\/p>\n<h3>Jenkinsfile:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npipeline {\r\n  agent any\r\n  parameters {\r\n    string(defaultValue: '', description: 'If you need to build a specific commit, enter it in this field.', name: 'GIT_COMMIT_ID')\r\n  }\r\n  stages {\r\n    stage('Checkout') {\r\n      steps {\r\n        script {\r\n          if ( env.GIT_COMMIT_ID.isEmpty() ) {\r\n            sh &quot;echo Checkout branch: $GIT_BRANCH_NAME&quot;\r\n            checkout([\r\n              $class: &quot;GitSCM&quot;,\r\n              branches: [[name: &quot;${GIT_BRANCH_NAME}&quot;]],\r\n              userRemoteConfigs: [[url: &quot;${GIT_URI}&quot;]]\r\n            ])\r\n          }\r\n          else {\r\n            sh &quot;echo Checkout commit: $GIT_COMMIT_ID&quot;\r\n            checkout([\r\n              $class: &quot;GitSCM&quot;,\r\n              branches: [[name: &quot;${GIT_COMMIT_ID}&quot;]],\r\n              userRemoteConfigs: [[url: &quot;${GIT_URI}&quot;]]\r\n            ])       \r\n          }\r\n        }\r\n      }\r\n    }\r\n  } \r\n}  \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Check if the value of the variable &quot;GIT_COMMIT_ID&quot; is set, if so, then do a checkout by the hash of the commit, if not, then do a checkout by the name of the branch. The variable &quot;GIT_BRANCH_NAME&quot; is taken from the Active Choice parameter. Jenkinsfile:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[613],"tags":[1411,617,1413,1415],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1751"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1751"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1751\/revisions"}],"predecessor-version":[{"id":1753,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1751\/revisions\/1753"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}