问题
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 {
}
}
回答1:
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()
}
}
来源:https://stackoverflow.com/questions/53743885/jenkins-array-variable-in-environment-tag-body