I am currently testing the pipeline approach of Jenkins 2.0 to see if it works for the build environment I am using.
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.
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.
Currently this is solved using the ReverseBuildTrigger
. But this thing stops working as soon as it gets anywhere close to a pipeline.
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.
Upstream Trigger You may subscribe to may upstream projects with specified trigger threshold. Unlike the build trigger in the upstream project which you can pass the parameters to the downstream build. The upstream trigger subsciption model does not offer parameters to pass information between builds.
Click New Item on your Jenkins home page, enter a name for your job, select Multibranch Pipeline, and click OK.
Step 1: From the Jenkins home page create a “new item”. Step 2: Select the “Multibranch pipeline” from the option and click ok. Step 3: Click “Add a Source” and select Github. Step 4: Under the credentials field, select Jenkins, and create a credential with your Github username and password.
If you're using a declarative multi-branch pipeline, you can use:
triggers { upstream(upstreamProjects: "some_project/some_branch", threshold: hudson.model.Result.SUCCESS) }
If you wish for branch matching to occur across dependencies you can use:
triggers { upstream(upstreamProjects: "some_project/" + env.BRANCH_NAME.replaceAll("/", "%2F"), threshold: hudson.model.Result.SUCCESS) }
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 ] ] ]), ])
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.
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.
(Someone else has asked a similar question Jenkins multi-branch pipeline and specifying upstream projects )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With