加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

访问Groovy脚本中的当前Jenkins构建

发布时间:2020-12-14 16:31:43 所属栏目:大数据 来源:网络整理
导读:我创建了一个Groovy脚本,该脚本在Jenkins作业的System Groovy Script步骤中使用,该作业需要访问当前作业的当前版本. 当使用Hudson.model Cause.UpstreamCause将当前作业的当前构建链接到我正在调度的依赖作业时,需要当前构建. 由于代码更简洁: 我在职step.g
我创建了一个Groovy脚本,该脚本在Jenkins作业的System Groovy Script步骤中使用,该作业需要访问当前作业的当前版本.

当使用Hudson.model Cause.UpstreamCause将当前作业的当前构建链接到我正在调度的依赖作业时,需要当前构建.

由于代码更简洁:

我在职step.groovy:

def scheduleDependentJob(jobName) {
  def fooParam = new StringParameterValue('foo','bar');
  def paramsAction = new ParametersAction(fooParam)

  println "Scheduling dependent job"
  def currentJob = ???
  def cause = new Cause.UpstreamCause(currentBuild)
  def causeAction = new hudson.model.CauseAction(cause)
  instance.queue.schedule(job,causeAction,paramsAction)
}

CauseAction构造函数(在http://javadoc.jenkins-ci.org/hudson/model/Cause.UpstreamCause.html上看到)需要一个Run对象,当前构建对象应该是该对象的实例.我只是找不到一个很好的方法来获取Groovy脚本中当前正在运行的作业.

解决方法

如果在Jenkins作业中使用的是 Groovy plug-in,那么在Execute system Groovy脚本步骤中,插件已经为您提供了一些预定义变量的访问权限:

build
    The current AbstractBuild.
launcher
    A Launcher.
listener
    A BuildListener.
out
    A PrintStream (listener.logger).

例如:

println build.getClass()

输出:

class hudson.model.FreeStyleBuild

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读