Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: How to make single job build and deploy on two servers

I have code in a repository. Now I want to create a job which will build code from the repository and deploy it on two servers.

Right now I create two jobs with exactly the same configuration. The only change is the server on which it needs to deploy.

Is it possible to do this with single job?

like image 709
javaMan Avatar asked Feb 22 '13 19:02

javaMan


People also ask

How do I deploy codes to multiple servers?

Setting up a server groupAdd a name for your server group, then select the default branch to deploy from. All servers within the group will then be deployed from the same branch. Next, you'll be able to choose how your servers are deployed, in parallel or sequentially.

How do I execute one Jenkins job after the other?

You can follow the below steps to trigger a Jenkins pipeline in another Jenkins pipeline. Select a job that triggers a remote one and then go to Job Configuration > Build section > Add Build Step > Trigger builds on remote/local projects option.

Can we run multiple builds in Jenkins?

Yes it's possible. Doc: If this option is checked, Jenkins will schedule and execute multiple builds concurrently (provided that you have sufficient executors and incoming build requests.)


2 Answers

Can I suggest to use this maven plugin. You can configure batch tasks (either maven goals, or scripts) that you can attach to your normal maven jobs.

https://wiki.jenkins-ci.org/display/JENKINS/Batch+Task+Plugin

Firstly, you have a Jenkins job that builds your job normally.

Then, using this plugin, you can configure two extra tasks on that same Jenkins job called, say, "Deploy-server-1" and "Deploy-server-2".

After you build your job, click on the "Task" button and you can easily run your deploy tasks.

So the process is:

-> build
     -> deploy server 1
     -> deploy server 2

If you have a look on the link I added for the Batch Tash Plugin, they have a single task called 'release'. Just imagine you can have more tasks right under it, to do whatever you want.

You probably need admin rights on your Jenkins server in order to install this plugin, if it's not there already...

like image 91
vikingsteve Avatar answered Oct 16 '22 15:10

vikingsteve


I solved this adding Flexible Publish plugin, and as a Conditional Action, using Run:'Always'. Now it is possible to add as many actions as like in Flexible publish conditional action, and all these actions can be 'Deploy WAR/EAR to container'.

like image 41
Sinisa Avatar answered Oct 16 '22 17:10

Sinisa