如何在常规动态参数上获取作业名称? [英] How to get the job name on a groovy dynamic parameter?

查看:79
本文介绍了如何在常规动态参数上获取作业名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此示例中,我需要获取名称作业,我有一个代码来获取带有该代码的build参数的先前值

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动态参数无法访问其余詹金斯工作所专有的常规环境变量.

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]

这篇关于如何在常规动态参数上获取作业名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆