Issue
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?
Solution
Groovy Dynamic parameters do not have access to the usual environment variables that the rest of the jenkins job is privy to.
Here is a working hack to get the job name:
def build = Thread.currentThread().toString()
def regexp= ".+?/job/([^/]+)/.*"
def match = build =~ regexp
def jobName = match[0][1]
Answered By - croesus