O. Shekriladze
O. Shekriladze

Reputation: 1536

Jenkins + Ansible for multistage application

Imagine I have project with two main branches, master(production) and development. I have one Jenkinsfile(one pipeline job triggered by git push event) with pipeline logic inside. From pipeline I invoke playbook to build and deploy application on server.

Now there is my situation, I want to have application deployed on two servers. One main server and one staging(development) server. when I push changes on master branch, I want changed application to be deployed on main(production) server, but when I push changes on development branch, I want to deploy changes on staging(development) server.

Now I have one Jenkinsfile, one playbook and it's inventory. when I push on master branch changes are deployed on main server.

But how can I manage the above scenario for development branch? should I have two jobs with two different Jenkinsfile(invoking different playbook which will deploy on different, staging server) on each branch? or should I have both Jenkinsfiles on both branches? or maybe this won't even work and I need some other idea?

I'm newbie in DevOps things like that and I would be grateful if someone help me out of this situation.

Upvotes: 0

Views: 400

Answers (1)

Piotr Wicijowski
Piotr Wicijowski

Reputation: 2115

What you are looking for is already implemented in Multibranch Pipeline plugin. It basically automatically creates a pipeline per branch, and then allows you to distinguish between which branch was used to run the pipeline. You can keep one Jenkinsfile and just extract the prod/staging specific differences and set them e.g. in environment variables.

Upvotes: 1

Related Questions