I have 3 environments, each on their own Virtual Network with their own configurations. Do I need to have 3 separate instances of Jenkins if I am to do Continuous Deployments on each of the environments? What are some best practices regrading deploying on a multi environment architecture?


This is a very good question as it is a common anti-pattern to couple ci/cd tools with environments.

Jenkins is a build factory. As such, it should be totally agnostic of the notion of environment, or even delivery.

The best pratice is to have some sort of staging process and / or interface (if you can afford it: a dedicated delivery software).

Staging process

You should try to create some sort of staging jobs for each environment, in which you'll define the configuration of the environment and bundle the final package with it.

Next you'll have delivery jobs for each environment.

Delivery tools

In order to do create the staging and delivery jobs, you may use very basic scripting tools, like shell, but there are more adapted scripting tools, like Ansible, puppet, chef...

If you can afford the expense, you may consider investing in a deployment software (I'll mention some that I worked with in the comments section).

Notice that those softwares manage some kind of environment staging process.

Obviously, it makes a lot of sens to combine deploy softwares and scripting.

Beyond segregating tools and environment

Since you asked for best practices, it appears to me that it is worth mentioning another commonly found anti-pattern: coupling SCM tools and delivery process.

It is a very good practice to store environment configuration (not passwords or confidential informations, of course) and go live scripts in SCM tools (like svn or git...). It is however a very bad practice to check-out environment configuration and go live scripts DURING the go live. It might simply be unavailable when you need it.

This check-out phase should be part of the staging process that I mentioned before.

Idem potence

Another best practice is that your scripts should be idem-potent: this means that you should be able to play your scripts once to perform the staging and delivery. Then you should be able to play them again and again, and they would not change the state of your system unless something chacked in the configuration.


As a final best practice I shall share from direct experice is scalling Jenkins: different teams have different needs and uses of Jenkins. When too many teams share a common Jenkins, there might be issues with resources. The worst case is when a team requires to restart the Jenkins master while another needs to deliver.

The ideal would be to have one Jenkins per team or per group of teams that share the same goal and delivery planning.


I've just transitioned away from having Jenkins freestyle jobs and having a seperate job for each environment to using Jenkins pipelines (declarative syntax).

In Jenkins pipelines we have a single file (Jenkinsfile) and define different stages for our different environments (Dev/Staging/Prod) and in those stages we just define different behaviour for each environment. For example, our 'Deploy' stage we will deploy to a different kubernetes namespace/cluster depending on if it's the development or staging environment.

I like this approach as you only have one Jenkinsfile per project that exists on all branches.

  • How do you make it deploy a specific environment then? Or do you always deploy all of them together?
    – lkraider
    Nov 11 '19 at 17:20
  • @lkraider the way we do this is using a good branching strategy in git and scripted Jenkins Pipeline. For example you can have all develop branch go to the dev environment and all master or any other branch go to stage or prod. Then in the your Jenkinsfile, you can use the "If" statement like "if (env.BRANCH_NAME == 'develop')" or "if (env.BRANCH_NAME == 'master')" in your pipeline stage. Take a look jenkins.io/doc/tutorials/build-a-multibranch-pipeline-project
    – Toye
    Mar 3 '20 at 16:21

The short answer to your question is no. Jenkins has no need to talk to your production environments but it can if you need it to. In other words, if Jenkins can reach these environments, it can likely interact with them.

From a best practices approach, typically I recommend using software that will make your deploy as simple and repeatable as possible (e.g. make, Ansible, Terraform, Cloud Formation or Kubernetes).

Pipelines are capable of handling parallel targets meaning you can build and deploy to all three environments at the same time if you choose to.

You might want to make your question more precise or detailed in order to garner more feedback.


We can use single Jenkinsfile for different environment. But we need something to differentiate between this environment, may be an environment variable or a parameter in a parameterised job to control what we need to do in each environment. May be we want to do build, test, perform e2e and push image into a repository in one environment. Then use the same image and deploy in the next ( staging, may be) and perform smoke test. Then use the same image to deploy into production.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.