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

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

问题描述

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

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.

我们有一个父项目,它使用 jenkins-cli 为源代码中找到的每个测试启动集成项目的构建.父项目和集成项目通过指纹匹配相关联.

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.

这种方法的问题在于聚合测试结果不起作用.我认为问题在于下游"集成测试是通过 jenkins-cli 启动的,因此 jenkins 没有意识到它们是下游.

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.

我查看了许多 jenkins 插件以尝试使其正常工作.Join 和 Parameterized Trigger 插件无济于事,因为它们期望构建项目的静态列表.参数化触发器可用的参数工厂也不起作用,因为没有工厂来创建任意参数列表.日志触发器插件将无法工作.

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.

Groovy Postbuild 插件看起来应该可以工作,但我不知道如何从中触发构建.

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) 

这最终对我有用.

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

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