Reputation:
I have groovy jenkins pipeline step and I want to pass for loop value as parameter to multiline sh
script in loop. But parameter is not getting passed.
Or if theres a better way to add step in jenkins stage?
for (int i = 0; i < elements.size(); i++) {
sh '''
cd terraform/
terraform init
terraform workspace select ${elements[i]}-${envtype}
terraform plan -var-file="./configs/${elements[i]}/var.tf"
'''
}
Upvotes: 5
Views: 5107
Reputation: 2683
You need a triple double quoted string. You are using a triple single quoted string. Any single quoted string in Groovy does not feature String interpolation, so '''${i}'''
prints ${i}
, while """${i}"""
prints 3
(if i = 3
).
Upvotes: 1
Reputation: 84854
It seems that you should use """
instead of '''
. '''
is triple single quoted String
and doesn't support interpolation.
Upvotes: 7