How to get the job name on a groovy dynamic parameter?

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

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]

Tags:

Groovy

Jenkins