I've two pipelines say - CallingPipeline and CalledPipeline where CallingPipeline calls CalledPipeline(downstream pipeline)
In CallingPipeline, I create an array and I want to pass it to CalledPipeline. For that, I need to create a Parameter in CalledPipeline but I could not find parameter which holds an array. Could you please suggest which Parameter will hold an array?
What if you just join() and made it a delimited string and then split()/reformed it back to a list/array in the CalledPipeline?
All jenkins parameters boil down to String or Boolean afaik
Use a string parameter. Serialize your data in CallingPipeline and deserialize it in CalledPipeline. This is a straightforward task using the Groovy classes JsonOutput and JsonSlurper. Compared to simple join / split this approach can be used even for more complex data (e. g. nested objects).
import groovy.json.JsonOutput
node {
stage('test') {
def myArray = [ 42, 'bar', 'baz' ]
build job: 'CalledPipeline', parameters: [
string(name: 'myParam', value: JsonOutput.toJson( myArray ) )
]
}
}
import groovy.json.JsonSlurper
node {
stage('test') {
echo "myParam: $myParam"
def myParamObject = new JsonSlurper().parseText( myParam )
for( def elem in myParamObject ) {
echo "$elem"
}
}
}
Output:
myParam: [42,"bar","baz"]
42
bar
baz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With