Suppose you want to start automatically a Jenkins Pipeline from another.
Besides, suppose you want to pass some variables from the first to the second one.
How can you do it?
Example
You have Pipeline 1 and Pipeline 2, and want to start Pipeline 2 from Pipeline 1
Pipeline 1
def params=[]
pipeline {
agent any
stages {
stage('Start pipeline2') {
script {
params.add(string(name: "field1", value: "value1")
params.add(string(name: "field2", value: "value2")
build(job: "path/to/pipeline2", parameters: params)
}
}
}
}
Pipeline 2
pipeline {
agent any
stages {
stage('Read parameters') {
script {
for (p in params) {
print p.key
print p.value
}
}
}
}
}
No comments:
Post a Comment