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

我是研究僧i 提交于 2020-08-21 19:42:28

问题


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?


回答1:


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...




回答2:


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'.




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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'] &amp;&amp; properties["app.server"] != "") {
      ant.project.executeTarget('deploy.server1')
    }
    if (properties['app.server2'] &amp;&amp; properties["app.server2"] != "") {
      ant.project.executeTarget('deploy.server2')
    }
  </groovy>
</target>


来源:https://stackoverflow.com/questions/15031415/jenkins-how-to-make-single-job-build-and-deploy-on-two-servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!