How to use Jenkins Multi-Configuration (Matrix) type Projects?

10.1k views Asked by At

Jenkins official Wiki page for Matrix projects isn't really helping me; so I have a few questions.

We're trying to build a couple of projects that are all essentially the same, just some are being branded differently for our customers. In other words, the software / tests / etc. are all identical, except for some tweaks to turn BrandA into BrandB (or BrandC, etc.)

I figure I should be using a Matrix project to create builds for BrandA, BrandB, etc. While I haven't figured out all my steps yet (including how to rename executables after they're built) I know that I will need to pass the Brand Name to many of my Jenkins Powershell scripts during the build process, and then use that brand n the script.

How do I get these variables into my scripts? Are they automatically passed in to every build step in Jenkins? What is the variable name to use?

Finally, is there a good resource on building these multi-configuration projects in Jenkins? I can't seem to find anything comprehensive online.

3

There are 3 answers

0
JZimmerman On BEST ANSWER

If you usually build the job for BrandA and only occasionally for BrandB and BrandC a matrix project may not be what you want. I recommend, instead, using a parameterized job where the brand is a parameter whose default value is BrandA. If the parameter is named BRAND the parameter is accessible in all of the builds and publish steps with ${BRAND} and as an environment variable as %BRAND%.

I refer you to the parameterized build wiki for more details.

0
aorfevre On

I'm not aware of that kind of process but I suggest you tu use the Copy project functionnality.

  1. New Job
  2. Copy From existing job

You will have a copy of your Job and you'll be able to setup easily all specific fields.

0
Bruno Volpato On

Yes, ${BRAND} and %BRAND% should work fine.

If you're using Maven, ${env.BRAND} does this too.

There's a plugin that you can see all Environment Variables that are available to your job/build. https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin