Reputation: 1162
I am trying to expand a variable in a Jenkinsfile. I first concatenate a couple of strings to create this variable and would like for it to be expanded so that it is interpreted as my environment variable.
I am looking for something like the exclamation mark !
in bash.
pipeline {
agent: any
environment:{
CRED_DEV_PROJ = "my_credentials"
}
stages {
stage("my_stage"){
steps{
script{
LST = [
["DEV", "PROJ"],
... some more lists ...
for (def i= 0; i < LST.size(); i++) {
CRED = "CRED_" + LST[i][0] + "_" + LST[i][1]
sshagent (credentials: [CRED]) {
... do stuff ...
}
}
}
}
}
}
The variable CRED
should be expanded so that it leads to my_credentials
, so that the line sshagent (credentials: [CRED])
is executed correctly.
Upvotes: 0
Views: 4845
Reputation: 5149
That should be env.“${CRED}“
.
See also my answer here: https://stackoverflow.com/a/51338110/4279361
Upvotes: 1