Jenkins Pipeline: Variable expansion issues

26 views
Skip to first unread message

Mike Craig

unread,
Mar 11, 2019, 6:33:08 PM3/11/19
to Jenkins Users
Hello,

The following snippet from my pipeline is acting very strangely, the values from the print statements are correct

              print "asgName: $asgName"
             print "asgMax: $asgMax"
             print "asgMin: $asgMin"
             asgIncrease = (asgMax * 2)
             print "Setting ASG size to ${asgIncrease}"
             sh ("aws autoscaling update-auto-scaling-group --min-size ${asgMin} --max-size ${asgMax} --region ${region} --auto-scaling-group-name ${asgName} ")


output

15:27:13  ecs_service_name: lab-us-west-2-lab-rat
[Pipeline] sh
15:27:14  + aws autoscaling describe-auto-scaling-groups --region us-west-2
15:27:14  + jq .AutoScalingGroupName
15:27:14  + jq '.AutoScalingGroups[]'
15:27:14  + jq 'select (.AutoScalingGroupName | contains ("lab-us-west-2-lab-rat"))'
[Pipeline] sh
15:27:18  + aws autoscaling describe-auto-scaling-groups --region us-west-2
15:27:18  + jq 'select (.AutoScalingGroupName | contains ("lab-us-west-2-lab-rat"))'
15:27:18  + jq .MaxSize
15:27:18  + jq '.AutoScalingGroups[]'
[Pipeline] sh
15:27:22  + jq 'select (.AutoScalingGroupName | contains ("lab-us-west-2-lab-rat"))'
15:27:22  + jq .MinSize
15:27:22  + jq '.AutoScalingGroups[]'
15:27:22  + aws autoscaling describe-auto-scaling-groups --region us-west-2
[Pipeline] echo
15:27:26  asgName: "lab-us-west-2-lab-rat-serviceInstanceAutoscalingGroup"
15:27:26  
[Pipeline] echo
15:27:26  asgMax: 1
15:27:26  
[Pipeline] echo
15:27:26  asgMin: 1
15:27:26  
[Pipeline] echo
15:27:26  Setting ASG size to 1
15:27:26  1
15:27:26  
[Pipeline] sh
15:27:26  + aws autoscaling update-auto-scaling-group --min-size 1
15:27:27  usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
15:27:27  To see help text, you can run:
15:27:27  
15:27:27    aws help
15:27:27    aws <command> help
15:27:27    aws <command> <subcommand> help
15:27:27  aws: error: argument --auto-scaling-group-name is required

2 things here, 
1. the asgIncrease variable should evaluate to 2, as I'm doubling the original variable.  
2 The line where the "aws autoscaling" command is executed does not expand and execute the entire line. I have tried hardcoding values here, and that seems to work, but how to use variables??


What am I doing wrong?

Thank you!



 

Reinhold Füreder

unread,
Mar 12, 2019, 10:18:14 AM3/12/19
to jenkins...@googlegroups.com

Hi Mike,

 

it looks like the variables are actually strings with a line break at the end, and not integers?

 

HTH Reinhold

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f6560954-54e3-4afd-a8cf-f76bd9de11c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mike Craig

unread,
Mar 12, 2019, 11:25:30 AM3/12/19
to Jenkins Users
Good thinking, I'll try to do a strip on them and see if that clears it up.
Reply all
Reply to author
Forward
0 new messages