Quantcast
Viewing all articles
Browse latest Browse all 520

Syntax error: "(" unexpected in Jenkins Groovy scripted pipeline

I have the following code in a Jenkins Groovy scripted pipeline.

cfn_template = sh(script: "aws --region $aws_region cloudformation get-template --stack-name $asg_cfn_stack_name --query 'TemplateBody' --output json", returnStdout: true).trim()echo "Debugging test line-2"def min_size = sh(script: "echo '${cfn_template}' | jq -r '.Resources.devfoenergybkrblueasgASG12345678.Properties.MinSize'", returnStdout: true).trim()

The first sh(script: "aws ... json").trim() is working fine and storing CFN template in to the Groovy variable cfn_template. However, the 3rd line is giving a syntax error.

Here are the relevant console log lines:

13:18:46  [Pipeline] sh13:18:46  + aws --region us-east-1 cloudformation get-template --stack-name dev-fo-energy-bkr-blue-asg --query TemplateBody --output json13:18:49  [Pipeline] echo13:18:49  Debugging test line-213:18:49  [Pipeline] sh13:18:50  /home/jenkins/agent/workspace/and_deployment_feature_AGM-448-2/cdk_build@tmp/durable-6410a3dd/script.sh: 700: Syntax error: "(" unexpected13:18:50  [Pipeline] echo13:18:50  Failure at CDK deployment. hudson.AbortException: script returned exit code 2

Please note that, I am trying to get the MinSize property of the Autoscaling Group (ASG) from the CFN template for a reason instead of getting it from the ASG itself.

What is the mistake here and how can I fix this?

I also have a Groovy variable asg_logical_id that sores the value devfoenergybkrblueasgASG12345678. I'd like to use this variable in the command that is giving syntax error now, instead of this direct value. I'm not sure if I face any other issue with that after passing the current issue. So, if you could please include it in your solution that would be helpful as well.

Update:

A typo in the first command (CFN) that was added after bring the command here from the code base has been removed.

The following two work on a Linux terminal:

cfn_template=$(aws --region $aws_region cloudformation get-template --stack-name $asg_cfn_stack_name --query 'TemplateBody' --output json)min_size=$(echo ${cfn_template} | jq -r '.Resources.devfoenergybkrblueasgASG12345678.Properties.MinSize')

Viewing all articles
Browse latest Browse all 520

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>