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
I got same problem, I'm about to solve it using multiple curl statements. See my post http://martin.podval.eu/2013/10/tomcat-7-remote-deployment.html Well, jenkins does not allow me to add multiple command line execution tasks, so I need to use three curl statements in one.
You can use Copy Artifact Plugin, where you can copy build artifacts one project to another. So you just have on job which builds what you need and it can be shared across other jobs.
You can deploy to multiple servers using the Node and Label parameter plugin.
Add the servers you want to deploy your code using Jenkins nodes: Manage Jenkins > Manage nodes > New node.
Be sure to add a label to each node so you can group them together and deploy to that group.
Create a new freestyle project and check the This project is parameterized option. Add a parameter and choose Label, and add the label you just created for your servers (nodes).
From here, every build step will replicate itself in each labeled node, so you can fetch your repository code using a SCM plugin, GitHub, GitLab, etc. or directly from your server, this is up to you, and the code will be deployed on each node.
Be aware that if your code need to be compiled, it will be compiled on the remote server. Also, every time this build is deployed to a node, will create an additional build in your build queue.
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...
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'.
I solved similar problem with ant tasks - getting server urls as input parameter from build.properties file. In my case there were several environments to support with same script, 1-2 servers on each.
<target name="deploy.application">
<groovy>
if (properties['app.server'] && properties["app.server"] != "") {
ant.project.executeTarget('deploy.server1')
}
if (properties['app.server2'] && properties["app.server2"] != "") {
ant.project.executeTarget('deploy.server2')
}
</groovy>
</target>