{"id":31664,"date":"2022-10-26T10:07:36","date_gmt":"2022-10-26T10:07:36","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=31664"},"modified":"2022-12-23T05:45:46","modified_gmt":"2022-12-23T05:45:46","slug":"jenkins-tutorials-jenkins-environment-variables-in-powershell","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/jenkins-tutorials-jenkins-environment-variables-in-powershell\/","title":{"rendered":"Jenkins Tutorials: Jenkins Environment Variables in PowerShell"},"content":{"rendered":"\n<p>The following variables are available to PowerShell scripts<\/p>\n\n\n\n<p>$ENV:BUILD_NUMBER<br>The current build number, such as &#8220;153&#8221;<\/p>\n\n\n\n<p>$ENV:BUILD_ID<br>The current build id, such as &#8220;2005-08-22_23-59-59&#8221; (YYYY-MM-DD_hh-mm-ss)<\/p>\n\n\n\n<p>$ENV:JOB_NAME<br>Name of the project of this build, such as &#8220;foo&#8221;<\/p>\n\n\n\n<p>$ENV:BUILD_TAG<br>String of &#8220;jenkins-${JOB_NAME}-${BUILD_NUMBER}&#8221;. Convenient to put into a resource file, a jar file, etc for easier identification.<\/p>\n\n\n\n<p>$ENV:EXECUTOR_NUMBER<br>The unique number that identifies the current executor (among executors of the same machine) that&#8217;s carrying out this build. This is the number you see in the &#8220;build executor status&#8221;, except that the number starts from 0, not 1.<\/p>\n\n\n\n<p>$ENV:NODE_NAME<br>Name of the slave if the build is on a slave, or &#8220;master&#8221; if run on master<\/p>\n\n\n\n<p>$ENV:NODE_LABELS<br>Whitespace-separated list of labels that the node is assigned.<\/p>\n\n\n\n<p>$ENV:JAVA_HOME<br>If your job is configured to use a specific JDK, this variable is set to the JAVA_HOME of the specified JDK. When this variable is set, PATH is also updated to have $JAVA_HOME\/bin.<\/p>\n\n\n\n<p>$ENV:WORKSPACE<br>The absolute path of the workspace.<\/p>\n\n\n\n<p>$ENV:HUDSON_URL<br>Full URL of Hudson, like http:\/\/server:port\/hudson\/<\/p>\n\n\n\n<p>$ENV:JENKINS_URL<br>Full URL of Jenkins, like http:\/\/server:port\/jenkins\/<\/p>\n\n\n\n<p>$ENV:BUILD_URL<br>Full URL of this build, like http:\/\/server:port\/jenkins\/job\/foo\/15\/<\/p>\n\n\n\n<p>$ENV:JOB_URL<br>Full URL of this job, like http:\/\/server:port\/jenkins\/job\/foo\/<\/p>\n\n\n\n<p>$ENV:SVN_REVISION<br>For Subversion-based projects, this variable contains the revision number of the module.<\/p>\n\n\n\n<p>$ENV:CVS_BRANCH<br>For CVS-based projects, this variable contains the branch of the module. If CVS is configured to check out the trunk, this environment variable will not be set.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">Compress-Archive $env:WORKSPACE\\\\POCStudentCrud\\\\bin\\\\app.publish $env:WORKSPACE\\\\POCStudentCrud\\\\bin\\\\app.publish.zip<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>","protected":false},"excerpt":{"rendered":"<p>The following variables are available to PowerShell scripts $ENV:BUILD_NUMBERThe current build number, such as &#8220;153&#8221; $ENV:BUILD_IDThe current build id, such as &#8220;2005-08-22_23-59-59&#8221; (YYYY-MM-DD_hh-mm-ss) $ENV:JOB_NAMEName of the project of this build, such as &#8220;foo&#8221; $ENV:BUILD_TAGString of &#8220;jenkins-${JOB_NAME}-${BUILD_NUMBER}&#8221;. Convenient to put into a resource file, a jar file, etc for easier identification. $ENV:EXECUTOR_NUMBERThe unique number that identifies&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","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":[],"class_list":["post-31664","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31664","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=31664"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31664\/revisions"}],"predecessor-version":[{"id":31665,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31664\/revisions\/31665"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=31664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=31664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=31664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}