How to get the jobname from jenkins

Jenkins

Jenkins Problem Overview


Is there a way to get the jobname for the current build in jenkins and pass it as a parameter to an ant build script?

Jenkins Solutions


Solution 1 - Jenkins

Jenkins sets some environment variables such as JOB_NAME (see here) for more details on the variables set.

You can then access these in ant via ${env.JOB_NAME}.

Edit: There's also a little howto for environment variables on the same page here.

Solution 2 - Jenkins

A similar issue, I was looking for job name for shell script.

In the 'Execute shell' > 'Command' textbox, both the below worked for me:

echo $JOB_NAME  
echo "$JOB_NAME"

Solution 3 - Jenkins

You may set special variable for that based on global variable. Simple:

THEJOB="${JOB_NAME.substring(JOB_NAME.lastIndexOf('/') + 1, JOB_NAME.length())}"

Now $THEJOB is your job name

Solution 4 - Jenkins

If you can run any Job, you can easily go to the Build section of that job and go to environment variables and see all the information there.

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkidlocoView Question on Stackoverflow
Solution 1 - JenkinsMartin FootView Answer on Stackoverflow
Solution 2 - JenkinsManohar Reddy PoreddyView Answer on Stackoverflow
Solution 3 - JenkinsСлава ЗСУView Answer on Stackoverflow
Solution 4 - Jenkinsjitendra nakraView Answer on Stackoverflow