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

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

问题描述

在这个例子中,我需要获取名称作业,我有一个代码用于获取构建参数的前一个值

  jenkins.model.Jenkins.instance.getItem( nameOfJob)lastBuild.getBuildVariables()获得( NameOfParameter)。 

作业的名称现在是硬编码的,我需要获取这个名字将是当前的名称工作,我怎么做不到?



谢谢

> Groovy动态参数无法访问其余jenkins作业所知道的常见环境变量。



下面是一个可以获取作业名称的工具:

  def build = Thread.currentThread()。toString()
def regexp =。+?/ job / ([^ /] +)/.*
def match = build =〜regexp
def jobName = match [0] [1]


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't I Do?

Thank you

解决方案

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]

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

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