Reputation: 326
I am getting an error message
Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
while running AWS CLI on Jenkins pipeline to create task definition for EC2 container service. The interesting thing is this script is able to run in command line without any error.
aws ecs register-task-definition --family ${FAMILY} --container-definitions "[{\"name\":\"wildfly\",\"image\":\"${REPOSITORY}\",\"memory\":3024,\"essential\":true,\"portMappings\":[{\"containerPort\":8080,\"hostPort\":8080,\"protocol\":\"tcp\"}]}]"`
This is the complete error message
aws ecs register-task-definition --family wildfly2-b47 --container-definitions [{name:wildfly, image:****/backend:b47, memory:3024, essential:true, portMappings:[{containerPort:8080, hostPort:8080, protocol:tcp}]}]
Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
This the jenkins stage code
stage('Deploy')
withCredentials([string(credentialsId: 'ecr-repository', variable: 'repo'),
[$class: 'AmazonWebServicesCredentialsBinding',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
credentialsId: 'ecr-credentials',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh '''
bash
set -x
export AWS_DEFAULT_REGION=us-west-2
CLUSTER="default"
VERSION=b${BUILD_NUMBER}
FAMILY=nxpmp2-${VERSION}
SERVICE="backend"
REPOSITORY=${repo}/backend:${VERSION}
#Register the task definition in the repository
aws ecs register-task-definition --family ${FAMILY} --container-definitions "[{"name": "wildfly", "image": ${REPOSITORY}, "memory": 3024, "essential": true, "portMappings": [{"containerPort": 8080, "hostPort": 8080, "protocol": "tcp" } ] }]"
#Update the Service
#aws ecs update-service --cluster ${CLUSTER} --region ${AWS_DEFAULT_REGION} --service ${SERVICE} --task-definition ${FAMILY}
--desired-count 1
'''
}
Please help me on this
Upvotes: 1
Views: 9535
Reputation: 1
The answer above me is problematic if you want to use some groovy variables inside your shell script in the pipeline.
The problem is that aws cli insist on a single quete and then you cant point your froovy variables as follow:
FOO = "bar"
sh'''
aws ecs ... --container-definitions '[{"name": $FOO}]'
'''
this will not give you bar as output but will give $FOO which will result in error. After a few hours of screwing around and failing to find a clean solution i found a workaround in this post Access a Groovy variable from within shell step in Jenkins pipeline
so the solution is
FOO = "bar"
sh'''
aws ecs ... --container-definitions '[{"name":''' + $FOO + '''}]'
'''
hope i helped
Upvotes: 0
Reputation: 37610
Have a look at the --container-definitions
part. You see it already with the syntax highlighting:
--container-definitions "[{"name":
You are using double quotes (around name
) inside double quotes.
The following should work instead:
--container-definitions '[{"name": ...}]'
Upvotes: 8