Managing multiplatform multibranch pipeline using Jenkins

32 views Asked by At

We are currently in the process of setting up a new automated build system for our c++ project. For this we will be using Jenkins to manage the build process.

When we start a build we would like to start 3 separate builds ( one for Windows, MacOS and Linux ) in parallel and collect the results. We would like to use a multibranch pipeline as currently each distinct version of our project is stored in a separate branch

A basic pipeline that could achieve this would be

node {
    // Prebuild stuff

    stage( 'Build' ) {
        def platforms = ['Windows', 'MacOS', 'Linux']

        for (platform in platforms) {
            def agentLabel = "${platform}_Agent"

            node(agentLabel) {
                // Build stuff
            }
        }
    }

    // Post build stuff
}

But I still have some questions:

Mainly:

  1. When each build pulls from the repository are they guaranteed to checkout the same commit. Or could it happen that if someone commits on the "wrong" time that one of the platforms builds a different version than the others.

Additionally:

  1. Does the "Include in changelog?" option for the checkout step still work when run in nested nodes?
  2. If I need to do some git queries (such as git rev-parse) in the prebuild phase, can I avoid having a separate repository for each branch?
  3. Is it better to have the root node be separate from the platform build nodes or is it ok to have the central node also be one of the platform nodes?
1

There are 1 answers

0
KamilCuk On

When each build pulls from the repository are they guaranteed to checkout the same commit. Or could it happen that if someone commits on the "wrong" time that one of the platforms builds a different version than the others.

I think yes. What we did, is the webhook that triggers the pipeline contains the commit ID to checkout that is then passed to git jenkins function. See https://www.jenkins.io/blog/2010/08/11/quiet-period-feature/ as a poor way of how jenkins tries to solve this.

You could checkout in the master node, save the commit id in a variable, and check the same commit id in all nodes.

Does the "Include in changelog?" option for the checkout step still work when run in nested nodes?

I think the git plugins sends the changelog as a notifications from worker to master. I think the end result will be that you will see the last checked out repository by the last executed node. https://plugins.jenkins.io/git/#plugin-content-changelog-extensions

If I need to do some git queries (such as git rev-parse) in the prebuild phase, can I avoid having a separate repository for each branch?

This depends on the specific implementation. You can have everything on NFS and use NFS and that way all will be shared.

Is it better to have the root node be separate from the platform build nodes or is it ok to have the central node also be one of the platform nodes?

It doesn't matter.