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

前端 未结 6 785
刺人心
刺人心 2021-02-06 15:37

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

相关标签:
6条回答
  • 2021-02-06 15:41

    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.

    0 讨论(0)
  • 2021-02-06 15:43

    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.

    0 讨论(0)
  • 2021-02-06 15:51

    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.

    0 讨论(0)
  • 2021-02-06 15:55

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

    0 讨论(0)
  • 2021-02-06 15:59

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

    0 讨论(0)
  • 2021-02-06 16:06

    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>
    
    0 讨论(0)
提交回复
热议问题