Triggering Remote Jenkins jobs from another Jenkins

Continuous integration and delivery is a very crucial part of software life cycle for automatic execution or deployment of the code. Usually we have single Jenkins for deployment, automation scripts etc. But many times different teams like Ops, Dev and QA create their own Jenkins for their own purposes.

Now if we talk about integrating everything at same place, it is not feasible to manage and re-create jobs. So solution is to make communication between two Jenkins servers and trigger build accordingly.

In this blog post, I will talk about how can you trigger a JOB-A (on remote-jenkins ) from JOB-B (on local-jenkins). The real scenario of this would be; when we are trying to trigger an automation script on Jenkins1 after successful completion of code deployment on Jenkins2.

For understanding this let assumes few things below-

  • We have a local job-ย  Job-B (local-jenkins) on server local-jenkins:8080
  • We have a remote job – Job-A (remote-jenkins) on server – remote-jenkins:8080

Now we want to trigger Job-A from Job-B. For achieving this we need to install few plugins in our local Jenkins (from which we want to trigger the job- local-jenkins in this case) –

Go to manage-Jenkins->configure system->Parameterized Remote Trigger Configuration, and do configuration as stated below-

remotetrigger1

You can add many remote servers. Now you have to do following changes in your local Jenkins job i.e. Job B.

buildsteps

buildinfo

Now save the configuration of your job and build your local job i.e. Job-B. Console of local job looks like below- local job

Console of Remote job looks like below – remotejob

You can see it says that started by local-Jenkins. So it has triggered this job on remote Jenkins from local Jenkins.

Similarly you can link multiple jobs to be build across different Jenkins server. I hope now you can easily integrate multiple Jenkins. Please add comments in case of any issues encountered. ๐Ÿ™‚

 

8 thoughts on “Triggering Remote Jenkins jobs from another Jenkins

    • Yes Harshi! we can do that, in-fact in background this whole thing is done by CLI itself.
      But when we have multiple jobs to configure and maintain, its easy to maintain using UI. And also if you have multiple/dynamic parameters, its little clumsy to handle with command line.
      Also as per cloudbees, Remote Jenkins CLI is security vulnerable.

      Like

  1. why I am getting below error …

    Connection to remote server failed [401], waiting for to retry – 10 seconds until next attempt. URL: http://10.238.117.163:8080/buildByToken/build, parameters:
    Retry attempt #1 out of 5
    [Oracle_JDK_8u112] $ sh -e /home/jenkins/tools/hudson.model.JDK/Oracle_JDK_8u112/hudson7898667382927918282.sh
    reuse cached crumb: 10.238.117.163
    Connection to remote server failed [401], waiting for to retry – 10 seconds until next attempt. URL: http://10.238.117.163:8080/buildByToken/build, parameters:

    Like

    • Hey Mahendra,

      401 is a unauthorised code, Please check if the user credentials you passed able to login to the Jenkins server. Recheck your credential supplied to Jenkinks configuration

      Like

Leave a comment