Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...