At times you encounter a use case where you need to run a Jenkins job remotely from another Jenkins instance. Well, there is a way to achieve this by using Parameterized Remote Trigger plugin.
Let’s see how we can trigger parameterized or non-parameterized jobs on remote Jenkins server from another Jenkins server.
Lets say we have two Jenkins server namely JenkinsOne and JenkinsTwo and we have a job name “TEST” on JenkinsTwo which we want to trigger from JenkinsOne.
To achieve the above stated task, we need to download Parameterized Remote Trigger Plugin on JenkinsOne. You can do that by clicking on Manage Jenkins option and then choosing Manage Plugins, wherein you can search and download the desired plugin.
Our JenkinsTwo server has password based access. So to trigger a job on it, first we need to log in to the server and then build the job. For this to happen from a remote server, we need to provide credentials to it. So before triggering a remote build on JenkinsOne, set the credentials by following the below mentioned steps.
Go to Manage Credentials option after choosing Manage Jenkins option on your console.
After that, choose add domain option. As our JenkinsTwo is a remote server so we need to specify its host name here.
After this specify the credentials so that we can log into JenkinsTwo. Since on the JenkinsTwo server we have password based authentication, we have to choose “Username with password” option as shown in the screenshot below.
Specify scope, username and password and save the changes.
Now go to Configure System option after selecting Manage Jenkins option. Under Parameterized Remote Trigger Configuration, click on Add.
As soon as we click on Add, the Display name field will automatically show already added remote Jenkins server which is JenkinsTwo. After checking the “Use the credentials Plugin” option, we can see the already provided credentials. Now to access the server, we need to provide JenkinsTwo address and port number.
Now make a new job in JenkinsOne. Here we are making this as a parameterized job, since our “TEST” job on JenkinsTwo is parameterized.
Now under the Build section, choose “Trigger a remotely parameterized job” option in the drop down menu of “Add build step” option as shown below.
After doing that, we can choose our remote Jenkins server in “Select a remote host” field.
Type the name of the job which you want to build on remote jenkins server i.e. “TEST” job on JenkinsTwo server in our case. Specify the parameter i.e “NAME” required by the “TEST” job. Also, we need to use the value defined here in “name” parameter as shown below. Save your configuration changes.
The final step remaining is to Build the job.
After building the job, in the Console Output we can see that the job has been remotely built if all the configuration changes have been made correctly.
On our remote server “JenkinsTwo”, if we can log in, we can verify that our job has been executed with the parameter’s value that was provided on JenkinsOne server and by the same user whose credentials we provided in the initial steps.