Rarm
Rarm

Reputation: 101

Display Name of the current opened job in Jenkins/Hudson

The code below displays a list of all jobs in hudson:

 def projectlist = hudson.model.Hudson.instance
 projectlist.getItems(hudson.model.Project).each
 {
     job ->println(job.displayName)
 }

How can I get the name of the current job only?

Upvotes: 2

Views: 10223

Answers (3)

Noam Manos
Noam Manos

Reputation: 16990

If you're using Groovy script within "Env Inject", you can get current build and current job by:

currentJob.getName()
currentBuild.toString()

Upvotes: 1

davdomin
davdomin

Reputation: 1219

With the next code you can get the Job Name in a Execute system Groovy script

this.binding.build.project.name

Upvotes: 4

KeepCalmAndCarryOn
KeepCalmAndCarryOn

Reputation: 9075

You can do this in groovy code within a groovy build step - https://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin

String jobName = System.getenv('JOB_NAME')

But it will also be available directly in any step in the job

e.g. shell

 echo "$JOB_NAME"

Taken from here How to get the job name on a groovy dynamic parameter in Jenkins

Upvotes: 2

Related Questions