A primary Jenkins set up is fairly boring. With none Jenkins plug-ins put in, there’s actually not a lot you are able to do with the device. With the Jenkins Maven plug-in, you’ll be able to run JUnit assessments and package deal Java functions. With the Jenkins Git plug-in put in, you’ll be able to pull code from a distant GitHub repository. However with none plug-ins, all you are able to do is create a Jenkins freestyle challenge, maybe parameterize a construct and possibly create a batch program or a shell script that references one thing from the Jenkins atmosphere variables record.
Nevertheless, having Jenkins inject atmosphere variables right into a construct job is an efficient technique to study among the underpinnings of the device. It is positively not a nasty concept to have an intimate data of the assorted entries within the Jenkins atmosphere variables record, which is the main target of this steady integration tutorial. The Jenkins atmosphere variables typically come in useful when you should write some superior shell scripts. Moreover, if you know the way to inject atmosphere variables into the Jenkins construct course of, it will probably open up an entire new world of technical alternatives, because it’ll provide you with entry to among the software program’s internals.
A straightforward technique to receive the Jenkins atmosphere variables record out of your native set up is to append env-vars.html to the server’s URL. For a regionally hosted Jenkins server, the URL could be: http://localhost:8080/env-vars.html.
The best technique to see how these Jenkins atmosphere variables work is to create a freestyle job, echo every entry within the record and see the worth Jenkins assigns to every property.
Step 1: Create a Jenkins freestyle challenge
From the Jenkins console, create a brand new freestyle challenge with the identify Jenkins-Setting-Variables-Checklist. There ought to be no areas within the identify, as clean characters may cause issues with the shell script. Click on OK to enter the construct job’s configuration web page.
For the outline of the merchandise, enter: Job to inject Jenkins atmosphere variables into the construct course of.
Step 2: Add a construct step
Scroll all the way down to the Construct part of the construct job’s configuration web page, click on the Add construct step drop-down field and select the Execute shell choice.
Enter the code beneath to inject Jenkins atmosphere variables into the construct script:
echo "BUILD_NUMBER" :: $BUILD_NUMBER
echo "BUILD_ID" :: $BUILD_ID
echo "BUILD_DISPLAY_NAME" :: $BUILD_DISPLAY_NAME
echo "JOB_NAME" :: $JOB_NAME
echo "JOB_BASE_NAME" :: $JOB_BASE_NAME
echo "BUILD_TAG" :: $BUILD_TAG
echo "EXECUTOR_NUMBER" :: $EXECUTOR_NUMBER
echo "NODE_NAME" :: $NODE_NAME
echo "NODE_LABELS" :: $NODE_LABELS
echo "WORKSPACE" :: $WORKSPACE
echo "JENKINS_HOME" :: $JENKINS_HOME
echo "JENKINS_URL" :: $JENKINS_URL
echo "BUILD_URL" ::$BUILD_URL
echo "JOB_URL" :: $JOB_URL
Jenkins inject atmosphere variables
Be aware that, on a home windows machine, the identical echo instructions can be utilized, however the Jenkins atmosphere variable ought to be bookended with share indicators, not preceded with a greenback signal as within the shell script.
Step 3: Run the construct job
With the Jenkins atmosphere variables record shell script entered and the construct job saved, merely run the job, and look at the output.
C:tutorial.jenkinsworkspace jenkins inject atmosphere variables>
"BUILD_ID" :: 2
"BUILD_DISPLAY_NAME" :: #2
"JOB_NAME" :: Jenkins Setting Variables Checklist
"JOB_BASE_NAME" :: Jenkins Setting Variables Checklist
"BUILD_TAG" :: jenkins Setting Variables Checklist 2
"EXECUTOR_NUMBER" :: 0
"NODE_NAME" :: grasp
"NODE_LABELS" :: grasp
"WORKSPACE" :: C:tutorial.jenkinsworkspaceJenkins Setting Variables Checklist
"JENKINS_HOME" :: C:tutorial.jenkins
"BUILD_URL" :: %
"JOB_URL" :: %
This console output was captured the second time the Jenkins construct job was run, so the BUILD_ID, BUILD_DISPLAY_NAME and BUILD_TAG variables embody the quantity two in them. Additionally, discover that the URL-related tags are all clean. That’s as a result of this job has not been configured as a remotely accessible job.
With none Jenkins plug-ins put in, there are just a few methods to reveal the device’s capabilities. Printing out the Jenkins atmosphere variables record is one such manner. An consciousness that these variables exist, together with a capability to make use of them, can play an necessary function when the time involves inject these listed atmosphere variables into superior Jenkins shell scripts.