Jenkins:触发上游变更的多分支管道 [英] Jenkins: Trigger Multi-branch pipeline on upstream change

查看:21
本文介绍了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.

目前每个存储库/分支都设置为 Matrix Project 用于不同的配置.每个项目都将其构建结果公开为工件,这些工件用于下游项目.

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天全站免登陆