Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "Parameterized Remote Trigger Plugin" in Jenkins Pipeline script?

I tried search but didn't find any example. I tried https://jenkins.io/doc/pipeline/examples/#trigger-job-on-all-nodes and got it is for the different nodes on the same Jenkins. I would like to trigger a build on another Jenkins. I configured the Remote Hosts and Authentication in system configuration of my Jenkins. How to call "Parameterized Remote Trigger Plugin" in Jenkins Pipeline script?

like image 267
user1599897 Avatar asked Jan 17 '17 09:01

user1599897


People also ask

How do you use a parameterized remote trigger plugin?

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.

How do I trigger Jenkins pipeline job remotely?

Create a remote Jenkins build trigger in three stepsCreate a Jenkins build job and enable the Trigger builds remotely checkbox. Provide an authentication token; This can be any text string of your choice. Invoke the Jenkins build URL to remotely trigger the build job.

What is the use of parameterized trigger plugin in Jenkins?

This plugin lets you trigger new builds when your build has completed, with various ways of specifying parameters for the new build. These new builds appear as "Subprojects" in the Jenkins UI when you are looking at a project that triggers them.

How do you trigger another job in Jenkins using pipeline with parameters?

You can follow the below steps to trigger a Jenkins pipeline in another Jenkins pipeline. Select a job that triggers a remote one and then go to Job Configuration > Build section > Add Build Step > Trigger builds on remote/local projects option.


2 Answers

Seems to be an open bug: https://issues.jenkins-ci.org/browse/JENKINS-38657

As a workaround you could create another job locally of an old type and use the plugin in the old school non pipeline script way. Then in your pipeline script you would just trigger this job. I know it's an ugly adapter but then you have parametrize this adapter and have it up and running for almost anything ;)

EDIT:

The bug 38657 is already closed, the plugin is available as pipeline step since 16th of May 2018. Usage should be as easy as:

//Trigger remote job
def handle = triggerRemoteJob(remoteJenkinsName: 'remoteJenkins', job: 'RemoteJob')

More information on the triggerRemoteJob step

like image 193
hakamairi Avatar answered Sep 27 '22 21:09

hakamairi


For anyone wondering how to do this using the Declarative Jenkinsfile Syntax:

steps {
   triggerRemoteJob remoteJenkinsName: 'configured-remote-jenkins-name', job: 'trigger-job-folder/trigger-job-name', blockBuildUntilComplete: true
}
like image 26
briceburg Avatar answered Sep 27 '22 22:09

briceburg