3

I have several Jenkins Pipeline jobs set up on my Jenkins installation all of them with a Jenkinsfile inside the repository.

These pipelines are run for all branches, and contains all steps necessary to build and deploy the branch. However, there are some differences for the different branches with regards to building and deploying them, and I would like to be able to configure different environment variables for the different branches.

Is that possible with Jenkins, or do I need to reevaluate my approach or use another CI system?

Hans Kristian
  • 1,786
  • 19
  • 25
  • 1
    [Read parameters from properties file](http://stackoverflow.com/questions/10427875/retrieve-parameters-from-properties-file) – Jignesh Feb 06 '17 at 13:57

2 Answers2

1

@rednax answer works if you're using a branch-per-environment git strategy. But if you're using git-flow (or any strategy where you assume that changes will be propogated up, possibly without human intervention, to master/production) you'll run into headaches where a merge will overwrite scripts/variables.

We use a set of folders which match the environment names : infrastructure/Jenkinsfile contains the common steps, and infrastructure/test/Jenkinsfile contains the steps specific to the test environment (the folders also contain Dockerfiles and cloudformation scripts). You could make that very complex with cascading includes or file merges, or simply have almost-identical copies of each file in each folder.

andrew lorien
  • 2,310
  • 1
  • 24
  • 30
-3

When configuring the job you can specify for Jenkins to grab the script (Jenkins file) from the branch on which you are running. This mean that technically you can adjust the script on each of your branches to set up parameters there. Or you can grab the script from the same source control location, but commit a configuration file in each of your branches and have the script read that file after the checkout.

rednax
  • 225
  • 1
  • 2
  • 13
  • This might be applicable to a small subset of environmental variables, but please include a warning that you should not have sensitive (dangerous, i.e. password) environmental variables in source control – Tielman Nieuwoudt Dec 13 '18 at 14:07
  • 1
    I took that as a given, there is no reason to store any credentials in pipelines or other files Jenkins gives you a way to securely store credentials and then use them in pipelines. – rednax Dec 14 '18 at 03:26