There's a Jenkins pipeline in an instance , say A. I want to call another pipeline from Jenkins instance B in one of the stages in Jenkins instance A. How do I write a groovy for that? I had a look at this answer but it wasn't useful for me.
Asked
Active
Viewed 1,172 times
2 Answers
0
You can use jenkins plugin Parameterized Remote Trigger
It's easy to use.
You just need to configure jenkins instance B in manage jenkins. It uses jenkins api in backend.
For groovy help you can check http://${JENKINS_URL}/pipeline-syntax

mayurssoni
- 66
- 5
-
For instructions on setting up Parameterized Remote Trigger: [Global Settings](https://github.com/jenkinsci/parameterized-remote-trigger-plugin/blob/master/README_SystemConfiguration.md) and [Pipeline Instructions](https://github.com/jenkinsci/parameterized-remote-trigger-plugin/blob/master/README_PipelineConfiguration.md) – Trisped Dec 29 '22 at 00:19
0
Option 1: You can use HttpBuilder to trigger a remote build. Still you would need the Parameterized Build plugin.
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.URLENC
def http = new HTTPBuilder( 'http://server/job/myjob/buildWithParameters' )
def postBody = [parameter: value] // will be url-encoded
http.post( path: '/', body: postBody,
requestContentType: URLENC ) { resp ->
println "POST Success: ${resp.statusLine}"
assert resp.statusLine.statusCode == 201
}
Option 2: Or use cURL like described here: https://stackoverflow.com/a/42947382/519852
Anyway, in both cases it would only trigger the build and not wait for it to finish nor get its result.

Matthias
- 1,200
- 2
- 13
- 33