This issue was resolved by Jesse Glick back in December of 2014 according to this JIRA: JENKINS-26194 <https://issues.jenkins-ci.org/browse/JENKINS-26194?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel>
All that is needed to access environment variables in the flow.groovy of a Workflow job in Jenkins is to use code like "env.BUILD_NUMBER" for the build number or for other environment variables. The available environment variables for your jenkins installation can be viewed at: http://[your-jenkins-server]:[your-jenkins-port-number]/env-vars.html The list mine comes up with is as follows: > > The following variables are available to shell scripts > BUILD_NUMBER > The current build number, such as "153" > BUILD_ID > The current build id, such as "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss) > BUILD_DISPLAY_NAME > The display name of the current build, which is something like "#153" by > default. > JOB_NAME > Name of the project of this build, such as "foo" or "foo/bar". (To strip > off folder paths from a Bourne shell script, try: ${JOB_NAME##*/}) > BUILD_TAG > String of "jenkins-*${JOB_NAME}*-*${BUILD_NUMBER}*". Convenient to put > into a resource file, a jar file, etc for easier identification. > EXECUTOR_NUMBER > The unique number that identifies the current executor (among executors of > the same machine) that’s carrying out this build. This is the number you > see in the "build executor status", except that the number starts from 0, > not 1. > NODE_NAME > Name of the slave if the build is on a slave, or "master" if run on master > NODE_LABELS > Whitespace-separated list of labels that the node is assigned. > WORKSPACE > The absolute path of the directory assigned to the build as a workspace. > JENKINS_HOME > The absolute path of the directory assigned on the master node for Jenkins > to store data. > JENKINS_URL > Full URL of Jenkins, like http://server:port/jenkins/ (note: only > available if *Jenkins URL* set in system configuration) > BUILD_URL > Full URL of this build, like http://server:port/jenkins/job/foo/15/ (*Jenkins > URL* must be set) > JOB_URL > Full URL of this job, like http://server:port/jenkins/job/foo/ (*Jenkins > URL* must be set) > SVN_REVISION > Subversion revision number that's currently checked out to the workspace, > such as "12345" > SVN_URL > Subversion URL that's currently checked out to the workspace. Here are a few of the top lines of my flow.groovy showing how to use these in a script: node('master') { // PULL IN ENVIRONMENT VARIABLES // Jenkins makes these variables available for each job it runs def buildNumber = env.BUILD_NUMBER def workspace = env.WORKSPACE def buildUrl = env.BUILD_URL // PRINT ENVIRONMENT TO JOB echo "workspace directory is $workspace" echo "build URL is $buildUrl" Yes, I think I could just echo "$env.BUILD_NUMBER" for those who are wondering. I didn't test doing so though I am sure it would work. Thank you Jesse for pointing this feature out in that JIRA post! In his post he gave a pointer to his GitHub post <https://github.com/jenkinsci/workflow-plugin/commit/d3e64f600fcb9bc2c4323abe138d23af90e9700f>to the TUTORIAL.MD <https://github.com/jenkinsci/workflow-plugin/blob/master/TUTORIAL.md> file showing how to use the environment variables in a script. -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e5753c66-4c4b-4d32-a048-0befee22dbd9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
