Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Multi-configuration projects with Jenkinsfile (build pipeline plugin)

I am trying to create a multi-configuration project that tests a bunch of builds that defines a compatibility matrix (for example by browser and os). I would like to define the steps for a single combination via Jenkinsfile.

How can I achieve this? I can create a pipeline parameterized build which depends on JenkinsFile but I can't figure out how to connect it to the multi-configuration build.

like image 344
Ankur Chauhan Avatar asked Apr 04 '16 21:04

Ankur Chauhan


1 Answers

It does not appear to be possible to have a Jenkinsfile as a buildstep in a multi-configuration project. A Jenkinsfile is used in a Pipeline job which is a jobtype aswell and Jenkins does not support (easy) conversion between jobtypes. In addition to that, a buildstep implies that it is run on a particular node in an executor slot. A Jenkinsfile however is evaluated on the master and itself defines buildsteps (with their node labels) which would inherently clash if it was run in a buildstep itself.

It is possible to trigger a pipeline through a multi-configuration job and supply it with the parameters from the multi-configuration job. (I also used the parameterized trigger plugin to do this)

My pipeline job has two text parameters, label and version with a example Jenkinsfile that looks like this:

node(this.label){
  println this.version   
}

My multi-configuration job has the following configuration:

  • A custom axis version with values alpha beta gamma and a slave axis label with a selected node
  • The buildstep "Trigger/call builds on other projects" to trigger my pipeline job with predefined parameters version=${version} and label=${label}

This setup leads to the pipeline job being called 3 times (as I have only one node selected), each time with a different version and running on my specified label. Here is one of the logs:

[Pipeline] node
Running on master in /var/lib/jenkins/jobs/pipelinejob/workspace
[Pipeline] {
[Pipeline] echo
gamma
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

This solution works if you only want to pass text based parameters or label names. It will be considerably trickier to use if you want to do something like "build with different jdks". I hope it is still helpful though.

like image 118
Bricktop Avatar answered Sep 21 '22 17:09

Bricktop