如何在jenkins中动态触发下游构建? [英] How do I dynamically trigger downstream builds in jenkins?

查看:842
本文介绍了如何在jenkins中动态触发下游构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望在jenkins的不同下游版本中动态触发集成测试。我们有一个参数化的集成测试项目,它将测试名称作为参数。我们从git repo动态确定我们的测试名称。



我们有一个父项目,使用jenkins-cli为每个测试中的源代码。父项目和集成项目通过匹配指纹相关。



这种方法的问题是聚合测试结果不起作用。我认为问题是下游整合测试是通过jenkins-cli开始的,所以詹金斯并没有意识到他们是下游的。



我看过很多jenkins插件试图让这个工作。连接和参数化触发器插件不能帮助,因为它们希望构建一个静态项目列表。参数化触发器可用的参数工厂将无法工作,因为没有工厂可以创建任意的参数列表。日志触发器插件将无法正常工作。



Groovy Postbuild插件看起来应该可以工作,但是我无法弄清楚如何从中触发构建。 / p>

解决方案

  def job = hudson.model.Hudson.instance.getJob(job) 
def params = new StringParameterValue('PARAMTEST',somestring)
def paramsAction = new ParametersAction(params)
def cause = new hudson.model.Cause.UpstreamCause(currentBuild)
def causeAction = new hudson.model.CauseAction(cause)
hudson.model.Hudson.instance.queue.schedule(job,0,causeAction,paramsAction)

这是最终为我工作的。


We want to dynamically trigger integration tests in different downstream builds in jenkins. We have a parametrized integration test project that takes a test name as a parameter. We dynamically determine our test names from the git repo.

We have a parent project that uses jenkins-cli to start a build of the integration project for each test found in the source code. The parent project and integration project are related via matching fingerprints.

The problem with this approach is that the aggregate test results doesn't work. I think the problem is that the "downstream" integration tests are started via jenkins-cli, so jenkins doesn't realize they are downstream.

I've looked at many jenkins plugins to try to get this working. The Join and Parameterized Trigger plugins don't help because they expect a static list of projects to build. The parameter factories available for Parameterized Trigger won't work either because there's no factory to create an arbitrary list of parameters. The Log Trigger plugin won't work.

The Groovy Postbuild Plugin looks like it should work, but I couldn't figure out how to trigger a build from it.

解决方案

def job = hudson.model.Hudson.instance.getJob("job")
def params = new StringParameterValue('PARAMTEST', "somestring")  
def paramsAction = new ParametersAction(params) 
def cause = new hudson.model.Cause.UpstreamCause(currentBuild)
def causeAction = new hudson.model.CauseAction(cause) 
hudson.model.Hudson.instance.queue.schedule(job, 0, causeAction, paramsAction) 

This is what finally worked for me.

这篇关于如何在jenkins中动态触发下游构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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