Jenkins surroundings variable listing for shell script construct job


A primary Jenkins set up is fairly boring. There actually is not a lot you are able to do with this instrument, with out putting in the Jenkins plug-in. With the Jenkins Maven plug-in, you’ll be able to run JUnit assessments and bundle 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, you’ll be able to simply construct a Jenkins freestyle challenge, possibly parameterize a construct and possibly create a batch program or shell script that references one thing from the Jenkins surroundings variables listing.

Nevertheless, injecting surroundings variables right into a Jenkins construct job is an efficient method to find out about a number of the underpinnings of the instrument. It is definitely not a nasty thought to have a radical data of the varied entries within the Jenkins surroundings variables listing, which is the main focus of this steady integration tutorial. Jenkins surroundings variables typically come in useful when it is advisable to write some superior shell scripts. Moreover, if you know the way to inject surroundings variables into the Jenkins construct course of, it might open up an entire new world of technical alternatives, because it provides you with entry to a number of the software program’s internals.

A simple method to get Jenkins surroundings variables listing out of your native set up is to connect env-vars.html for the URL of the server. For a domestically hosted Jenkins server, the URL could be: http://localhost:8080/env-vars.html,

The simplest method to see how these Jenkins surroundings variables work is to create a freestyle job, echo every entry within the listing, and take a look at the worth assigned to every property by Jenkins.

Whole Jenkins Surroundings Variables Record.

Step 1: Create Jenkins Freestyle Challenge

From the Jenkins console, create a brand new Freestyle challenge with the identify jenkins-environment-variable-list, The identify should not include any areas, as clean characters could cause issues with shell scripts. Click on OK to enter the construct job’s configuration web page.

jenkins freestyle
Creating Jenkins Surroundings Variables Record Freestyle Job.

For merchandise description, enter: Operate to inject Jenkins surroundings variables into construct course of,

Step 2: Add a Construct Part

scroll down Make Within the part of the Construct Job’s Configuration web page, click on add construct step drop-down field and choose execute shell different.

jenkins shell script
Add a Jenkins shell script to inject surroundings variables into the construct course of.

Enter the code under to inject Jenkins surroundings 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 surroundings variables

Be aware that, on a home windows machine, the identical echo command can be utilized, however Jenkins surroundings variables should be booked with % indicators, not preceded by a greenback sign up shell scripts.

batch order
The syntax for batch instructions with shell scripts is to make use of two % indicators as a substitute of the main greenback signal.

Step 3: Run the Construct Activity

With Jenkins surroundings variables listing entered shell script and construct activity saved, simply run the job, and examine the output.

C:tutorial.jenkinsworkspace jenkins inject surroundings variables>
"BUILD_ID" :: 2
"BUILD_DISPLAY_NAME" :: #2
"JOB_NAME" :: Jenkins Surroundings Variables Record
"JOB_BASE_NAME" :: Jenkins Surroundings Variables Record
"BUILD_TAG" :: jenkins Surroundings Variables Record 2
"EXECUTOR_NUMBER" :: 0
"NODE_NAME" :: grasp
"NODE_LABELS" :: grasp
"WORKSPACE" :: C:tutorial.jenkinsworkspaceJenkins Surroundings Variables Record
"JENKINS_HOME" :: C:tutorial.jenkins
"JENKINS_URL" ::
"BUILD_URL" :: %
"JOB_URL" :: %
Completed: SUCCESS

This console output was captured the second time the Jenkins construct job was run, so BUILD_ID, BUILD_DISPLAY_NAME And BUILD_TAG Variables they include the quantity two. Additionally, be aware that the URL-related tags are all clean. It’s because this activity just isn’t configured as a remotely accessible activity.

There are just a few methods to show the instrument’s capabilities, with out having to put in the Jenkins plug-in. Printing the Jenkins surroundings variable listing is one such manner. An consciousness that these variables exist, together with the flexibility to make use of them, can play an necessary position when it comes time to inject these listed surroundings variables into superior Jenkins shell scripts.



Supply hyperlink

Related Posts