使用Groovy在与父节点相同的节点上触发Jenkins作业 [英] Trigger Jenkins job on same node than parent with Groovy

查看:76
本文介绍了使用Groovy在与父节点相同的节点上触发Jenkins作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jenkins作业中,我想从Groovy脚本触发另一个Jenkins作业:

In a Jenkins job, I want to trigger another Jenkins job from a Groovy script :

other_job.scheduleBuild();

但是other_job不在与父作业相同的节点上启动.如何修改脚本以在与父作业相同的节点上启动other_job?

But other_job is not launched on the same node than the parent job. How can I modify my script to launch other_job on the same node than the parent job ?

我以前是使用在其他项目上触发/调用"和"NodeLabel参数"插件来完成此操作的,但现在我想在脚本中执行此操作.

I used to do that with the "Trigger/call builds on other project" and "NodeLabel Parameter" plugins but I would like now to do that inside a script.

推荐答案

基于biruk1230的答案,这是一个完整的解决方案:

Based on the answer of biruk1230, here is a full solution :

import hudson.model.*;
import jenkins.model.Jenkins
import java.util.concurrent.*
import hudson.AbortException
import org.jvnet.jenkins.plugins.nodelabelparameter.*

def currentBuild = Thread.currentThread().executable
current_node = currentBuild.getBuiltOn().getNodeName()

def j = Hudson.instance.getJob('MyJobName')
try {
  def params = [
    new NodeParameterValue('node', current_node, current_node),
  ]
  def future = j.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(params))
  println "Waiting for the completion of " + j.getName()
  anotherBuild = future.get()
} catch (CancellationException x) {
  throw new AbortException("aborted.")
}

这篇关于使用Groovy在与父节点相同的节点上触发Jenkins作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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