I need get the name job in this example, I have a code for get the previous value of the build parameter with that code
jenkins.model.Jenkins.instance.getItem("nameOfJob").lastBuild.getBuildVariables().get("NameOfParameter");
The name of job now is hard coded, I need get this name will be the name of the current job. How can I do it?
Following works for me from the uno-choice plugin parameter Groovy script (means before the build is bound):
def job = this.binding.jenkinsProject
If you're interested in the job name, then:
def jobName = this.binding.jenkinsProject.name
Firstly be sure you use "Execute system Groovy script" step (not "Execute Groovy script").
The simplest answer for getting the job name is:
String JOB_NAME = build.project.name;
And just use JOB_NAME
like you would in a shell script.
But since you actually need a job instance then use:
build.project.lastBuild.getBuildVariables().get("NameOfParameter");
BUT, to get parameters for current build (actually running at the moment) simply use:
// string
// (bool is also a string -- "true"/"false" string)
def someStr = build.buildVariableResolver.resolve("someBuildParam");
// mapping to int
def someInt = build.buildVariableResolver.resolve("someBuildParam") as int;
Class names in Jenkins documentation are a bit tricky, so here are some tips:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With