Salini Sanju
Salini Sanju

Reputation: 21

Need to get jenkins build number

In my Jenkins job configure section I am calling an expect script to run.I need to get the current build number value in a variable in the expect script. is it possible to get the build number in a variable? example. in my Jenkins job i am calling an expect script sample_text.exp in which i need to get current build number in a variable Build_no is it possible?

Upvotes: 1

Views: 15672

Answers (2)

Mayur Nagekar
Mayur Nagekar

Reputation: 821

Very much possible. You can use the environment variable, BUILD_NUMBER for that in execute shell section. To get a list of all the environment variables that one can use, go to

<your_jenkins_url>/env-vars.html

For example:

http://my-jenkins-box:8080/env-vars.html

Logic that I spoke off in my below comment

if [ -z ${JOB_URL} ]; then
   echo "*************************** This is not a Jenkins build ***********"
   # Do your stuff here :)
else
   echo "**************************** This is a jenkins build so maven project is built before this script is executed via Jenkins ***************************"
fi

Also, remember that if you are running your script with sudo, these environment variables will not be available then

Upvotes: 3

jussuper
jussuper

Reputation: 3527

yes, it is possible. There is environment variable BUILD_NUMBER. What you mean by "Jenkins job configure section"? In "Execute Windows batch command" in (build section) you can do:

echo %BUILD_NUMBER%

to get this number in a different variable:

set "BUILD_NO=%BUILD_NUMBER%" echo %BUILD_NO%

Upvotes: 5

Related Questions