IT:AD:Jenkins:HowTo:Work with the Environment Variables
Summary
As already expressed in the IT:AD:Jenkins:Glossary, each time Jenkins starts a new Build it copies into the shell the normal system Environment Variables/, but also a sets a couple of custom temporary ones (they will be lost when the Build process completes) that are unique to that build.
Notes
The following basic environment fields are always available to shell scripts, but additional Plugins can define others.
- BUILDNUMBER: The current build number, such as “153” * BUILDID: The current build id, such as “2005-08-2223-59-59” (YYYY-MM-DDhh-mm-ss)
- JOBNAME: Name of the project of this build, such as “foo” or “foo/bar” * BUILDTAG: String of “jenkins-${JOBNAME}-${BUILDNUMBER}”. Convenient to put into a resource file, a jar file, etc for easier identification.
- EXECUTORNUMBER: 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. * NODENAME: Name of the slave if the build is on a slave, or “master” if run on master
- NODELABELS: Whitespace-separated list of labels that the node is assigned. * WORKSPACE:The absolute path of the directory assigned to the build as a workspace. * JENKINSHOME: The absolute path of the directory assigned on the master node for Jenkins to store data.
- JENKINSURL: Full URL of Jenkins, like http://server:port/jenkins/ * BUILDURL: Full URL of this build, like http://server:port/jenkins/job/foo/15/
- JOB_URL: Full URL of this job, like http://server:port/jenkins/job/foo/</sxh>
More can be seen here:
-
- GITCOMMIT: For Git-based projects, this variable contains the Gitish of the commit checked out for the build * GITBRANCH: For Git-based projects, this variable contains the Git branch that was checked out for the build (normally master)
An example of usage: * IT:AD:Jenkins:HowTo:Invoke a PreBuild Batch Command