How to get the jobname from jenkins

Solution 1:

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:

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:

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