如何在 groovy 动态参数上获取作业名称? [英] How to get the job name on a groovy dynamic parameter?
本文介绍了如何在 groovy 动态参数上获取作业名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此示例中我需要获取名称作业,我有一个代码用于使用该代码获取构建参数的先前值
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?
推荐答案
Groovy 动态参数无法访问 jenkins 作业的其余部分所知道的常用环境变量.
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]
这篇关于如何在 groovy 动态参数上获取作业名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文