<p>You can use the Jenkins pipeline (Jenkinsfile) to run the multiple branches in multiple stages, with the conditional 'IF'.
Below is an example from Jonico. I always use this example to create continuous delivery of monolithic  applications.
<a href="https://gist.github.com/jonico/e205b16cf07451b2f475543cf1541e70" rel="nofollow noreferrer">https://gist.github.com/jonico/e205b16cf07451b2f475543cf1541e70</a></p>

CC BY-SA 4.0
2018-09-17T19:44:10.857Z
2018-09-17T20:13:29.443Z
2018-09-17T20:13:29.443Z
dalmo.santos
<p>To be honest, I'm not sure exactly what your question is here (StackExchange sites usually work best when you formulate your post as a single question rather than just generally asking for help).  So I'm going to attempt to address what appears to be your main issue:</p>

<blockquote>
  <p>Setting up 9 jobs that are very similar feels like I'm doing something wrong. I've considered a matrix per platform with branch axis, but I'll also need to report on build status/outputs, and having 6 outputs tied into one job might be problematic. Tests may also differ between branches as features are changed.</p>
</blockquote>

<p>This is where <a href="https://jenkins.io/doc/book/pipeline/shared-libraries/" rel="nofollow noreferrer">Shared Libraries</a> come in.  Jenkins Shared Libraries allow you to refactor common code into their own individual repositories outside of your project repos.  This allows you to treat your Pipeline code, or snippets of your Pipeline code, as independently-versioned libraries.</p>

<p>For instance, my team has 150+ repos which require near-identical Pipelines.  Instead of synchronizing 150 Jenkinsfiles, I have one Shared Library which is used by all of these repos to run tests and deploys.</p>

CC BY-SA 4.0
2018-09-17T23:17:15.250Z
2018-09-17T23:17:15.250Z
jayhendren
<p>I've never done any CI work before, so I'm struggling to decide how to set up Jenkins as my first project at my new job.</p>

<p>From what I (sort of) understand:</p>

<ul>
<li><p>Jobs are the generic work unit</p></li>
<li><p>Pipelines are like a job but are defined from  a series of steps from  scripts stored in a VCS repo</p></li>
<li><p>Matrix is like a job, but you can define axes to execute commands across</p></li>
</ul>

<p>The basic setup for my project is 2 git repositories serving 3 platforms (one Windows, one Mac/Unix), each of which has 3 branches for different phases (so 9 builds total). The team wants something that will automate builds from each branch as things are committed to them, and then run some tests (which I'm also going to write). There are 2 machines dedicated to each branch. This will not include any kind of general deployment. It'll only be to the test machines.</p>

<p>I've set up a Jenkins master server that each branch stack connects to. I have 3 jobs set up at the moment targets a label I've assigned to the test machines, since I'm just testing with one branch for each platform. Each job uses the "run script" option, and contains something like: </p>

<pre><code># sets up the required authentication
$SLAVE_HOME/pre-build.sh

# then run the build script
./build.sh

# then a post-build/install script that automates installation of the packages,
# runs the product, and verifies it's started properly.
$SLAVE_HOME/install.sh
</code></pre>

<p>The scripts are unique to platform, and may eventually be unique to branch depending on if build steps change</p>

<p>I'll also need to integrate testing at some point - I'm planning to try using SikuliX for mac/unix and either that or Selenium+Winium for Windows. This will include aggregating results and build status to post on a not-yet-written monitoring page. That will add another couple platform-specific "global" steps.</p>

<p>Setting up 9 jobs that are very similar feels like I'm doing something wrong. I've considered a matrix per platform with branch axis, but I'll also need to report on build status/outputs, and having 6 outputs tied into one job might be problematic. Tests may also differ between branches as features are changed.</p>

<jenkins><jenkins-pipeline>
Jenkins pipelines vs matrix vs multiple jobs for multiple branches across multiple platforms
mgwio
# Jenkins pipelines vs matrix vs multiple jobs for multiple branches across multiple platforms

(Asked by: username_0 on 2018-09-17)

I've never done any CI work before, so I'm struggling to decide how to set up Jenkins as my first project at my new job.
From what I (sort of) understand:

Jobs are the generic work unit
Pipelines are like a job but are defined from  a series of steps from  scripts stored in a VCS repo
Matrix is like a job, but you can define axes to execute commands across

The basic setup for my project is 2 git repositories serving 3 platforms (one Windows, one Mac/Unix), each of which has 3 branches for different phases (so 9 builds total). The team wants something that will automate builds from each branch as things are committed to them, and then run some tests (which I'm also going to write). There are 2 machines dedicated to each branch. This will not include any kind of general deployment. It'll only be to the test machines.
I've set up a Jenkins master server that each branch stack connects to. I have 3 jobs set up at the moment targets a label I've assigned to the test machines, since I'm just testing with one branch for each platform. Each job uses the "run script" option, and contains something like: 
# sets up the required authentication
$SLAVE_HOME/pre-build.sh

# then run the build script
./build.sh

# then a post-build/install script that automates installation of the packages,
# runs the product, and verifies it's started properly.
$SLAVE_HOME/install.sh

The scripts are unique to platform, and may eventually be unique to branch depending on if build steps change
I'll also need to integrate testing at some point - I'm planning to try using SikuliX for mac/unix and either that or Selenium+Winium for Windows. This will include aggregating results and build status to post on a not-yet-written monitoring page. That will add another couple platform-specific "global" steps.
Setting up 9 jobs that are very similar feels like I'm doing something wrong. I've considered a matrix per platform with branch axis, but I'll also need to report on build status/outputs, and having 6 outputs tied into one job might be problematic. Tests may also differ between branches as features are changed.

**Tags:** jenkins, jenkins-pipeline


---

## 2 answers

### Answer by username_1 on 2018-09-17. Score: 2

You can use the Jenkins pipeline (Jenkinsfile) to run the multiple branches in multiple stages, with the conditional 'IF'.
Below is an example from Jonico. I always use this example to create continuous delivery of monolithic applications.
<https://gist.github.com/jonico/e205b16cf07451b2f475543cf1541e70>


---

### Answer by username_2 on 2018-09-17. Score: 1

To be honest, I'm not sure exactly what your question is here (StackExchange sites usually work best when you formulate your post as a single question rather than just generally asking for help). So I'm going to attempt to address what appears to be your main issue:

> Setting up 9 jobs that are very similar feels like I'm doing something wrong. I've considered a matrix per platform with branch axis, but I'll also need to report on build status/outputs, and having 6 outputs tied into one job might be problematic. Tests may also differ between branches as features are changed.

This is where [Shared Libraries](https://jenkins.io/doc/book/pipeline/shared-libraries/) come in. Jenkins Shared Libraries allow you to refactor common code into their own individual repositories outside of your project repos. This allows you to treat your Pipeline code, or snippets of your Pipeline code, as independently-versioned libraries.

For instance, my team has 150+ repos which require near-identical Pipelines. Instead of synchronizing 150 Jenkinsfiles, I have one Shared Library which is used by all of these repos to run tests and deploys.


---

