詹金斯(Jenkins):在上游变更时触发多分支流水线 [英] Jenkins: Trigger Multi-branch pipeline on upstream change

查看:313
本文介绍了詹金斯(Jenkins):在上游变更时触发多分支流水线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在测试Jenkins 2.0的管道方法,以查看它是否适用于我正在使用的构建环境.

I am currently testing the pipeline approach of Jenkins 2.0 to see if it works for the build environment I am using.

首先关于环境本身.当前,它由多个SCM存储库组成.每个存储库都包含多个分支,用于开发的不同阶段,并且每个分支都使用多种配置构建.并非所有配置都适用于每个存储库.

First about the environment itself. It currently consists of multiple SCM repositories. Each repository contains multiple branches, for the different stages of the development and each branch is build with multiple configurations. Not all configurations apply to every repository.

当前,每个存储库/分支都被设置为

Currently every repository/branch is setup as a Matrix Project for the different configurations. Each project exposes it's building results as a artifact and these artifacts are used in the downstream projects.

不同的存储库彼此依赖,因此在上游作业上成功构建会触发某些特定的下游作业.目前,所有这些都可以正常工作,但是由于需要手动更改许多不同的项目,因此设置新分支或调整构建过程所需的工作量很多.

The different repositories depend on each other, so a successful build on a upstream job triggers some specific down stream jobs. Currently all that works, but the amount of work required to setup a new branch or to tweak the building process is a lot, since many different projects need to be altered by hand.

现在,我想尝试一下新的管道.我的想法是创建多分支管道项目,并在包含构建说明的资源库中放置一个Jenkinsfile.

Now I wanted to give the new pipelines a try. My idea was to create multi-branch pipeline projects and place a Jenkinsfile inside the repository containing the instructions for the build.

主要问题是使构建彼此触发,因为基本上在特定上游分支中的构建需要触发下游分支.上游项目并不知道需要触发哪些下游分支的信息.每个下游项目都从一些上游分支获取工件,而理想的解决方案是,如果作为工件的来源的上游构建完成了构建,则将触发下游构建.

The main problem is getting the builds to trigger each other, because basically a build in a specific upstream branch, needs to trigger a downstream branch. How ever the information what downstream branches need to be triggered is not known to the upstream project. Each downstream project fetches the artifacts from some upstream branches and the ideal solution would be if the downstream build would be triggered in case the upstream build that is the source for the artifact finishes it's build.

问题在于,只有下游项目才真正知道它们需要什么工件.在大多数情况下,分支名称不太可能匹配,这使得从上游项目触发构建非常困难.

The problem is only the downstream projects really know what artifacts they require. The branch names are unlikely to match in most cases and that makes triggering the builds from the upstream project very difficult.

当前,使用 ReverseBuildTrigger .但是,只要它到达管道附近的任何地方,它都会停止工作.

Currently this is solved using the ReverseBuildTrigger. But this thing stops working as soon as it gets anywhere close to a pipeline.

我真的很茫然如何使它工作.有什么办法可以得到 ReverseBuildTrigger 在管道脚本中工作?

I am really at a loss how to get this working. Is there any way to get something like the ReverseBuildTrigger working inside pipeline scripts?

如果更改单个上游分支,也不触发所有分支的整个下游构建.这将创建太多相等的构建.

Also triggering the entire downstream build for all branches in case a single branch upstream is changed is not a option. This would create far too many equal builds.

推荐答案

我目前正在尝试使其适用于我们的部署. 我最接近的是将以下内容添加到下游的Jenkinsfile;

I'm currently trying to get this to work for our deployment. The closest I've got is adding the following to the downstream Jenkinsfile;

properties([
    pipelineTriggers([
        triggers: [
            [
                $class: 'jenkins.triggers.ReverseBuildTrigger',
                upstreamProjects: "some_project", threshold: hudson.model.Result.SUCCESS
            ]
        ]
    ]),
])

这至少让詹金斯(Jenkins)意识到它应该在以下情况下触发 构建了"some_project"获取程序,即显示在查看配置"页面中.

That at least gets Jenkins to acknowledge that it should be triggering when 'some_project' get's built i.e it appears in the "View Configuration" page.

但是到目前为止,"some_project"的构建仍然不会触发下游 项目按预期进行.

However so far builds of 'some_project' still don't trigger the downstream project as expected.

话虽这么说,也许您会有更多的运气. 让我知道它是否对您有用.

That being said maybe you'll have more luck. Let me know if it works for you.

(其他人也提出了类似的问题 Jenkins多分支管道并指定上游项目)

(Someone else has asked a similar question Jenkins multi-branch pipeline and specifying upstream projects )

这篇关于詹金斯(Jenkins):在上游变更时触发多分支流水线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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