Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Post Build Task access jenkins environment variables like JOB_NAME

I want to get the job details in Post Build Task plugin and pass the details to the batch/ powershell for further processing.

I am not able to access the Jenkins environment variables like JOB_NAME, JOB_ID etc.

In Post Build Plugin task

Log text "BUILD SUCCESSFUL" OPTION

Script Block: run.bat $JOB_NAME-$JOB_ID

I need to pass the $JOB_NAME-$JOB_ID to the script.

like image 893
Dolly USa Avatar asked Nov 13 '13 00:11

Dolly USa


People also ask

Which environmental variables in Jenkins is set to the URL of the Jenkins master that is responsible for running the build?

Jenkins Set Environment Variables Equals 'master' for master node. Name of the project of this build. This is the name you gave your job when you first set it up.

What is Jenkins build environment?

This plugin shows information about the environment of a build and gives the option to compare the environments of two builds.


Video Answer


2 Answers

Build Parameters are accesses as $Name in the Execute shell and post build section. You can use

$JOB_NAME 
$BUILD_NUMBER

for name of job and build number which is same as JOB_ID.

Also Set "Jenkins user build variables" to get more info regarding Environment variables.

like image 161
Triangle Avatar answered Nov 08 '22 22:11

Triangle


Generally the sintax for accessing variables is the following:

${VARIABLE}

but in some cases, especially when you are trying to access variables using during the build, this sintax can be used:

${ENV, var="VARIABLE"}

That in my case is working also when you have a parameterized build.

like image 34
carlo.bongiovanni Avatar answered Nov 08 '22 21:11

carlo.bongiovanni