I would like to define an array of strings within the environment tag/body of the Jenkins pipeline. This doesn't seem to work; jenkins doesn't recognize the array.
Environment variable values must either be single quoted, double quoted, or function calls. @ line x, column y. myArray= [
pipeline {
agent {
label 'Test'
}
environment {
myArray = [
"Item1",
"Item2",
"Item3"
]
}
}
The next code seems to work, but I would like to have all fields/ settings in the environment tag.
def myArray = [
"Item1",
"Item2",
"Item3"
]
pipeline {
agent {
label 'Test'
}
environment {
}
}
Environment variable values must either be single quoted, double quoted, or function calls.
You can define a function which will return your array.
def getArray(){
return ['Item1', 'Item2', 'Item3']
}
pipeline {
agent {
label 'Test'
}
environment {
ARRAY=getArray()
}
}
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