Following command works on bash shell but YAML parser (bitbucket-pipelines.yaml) reports it as invalid syntax
- export TASK_VERSION=$(aws ecs register-task-definition --family MyTask --container-definitions "[{\"name\":\"MyContainer\",\"image\":\"1234567.dkr.ecr.us-west-1.amazonaws.com/ecs-repository:1.0.13\",\"cpu\":50,\"portMappings\": [{\"hostPort\": 80,\"containerPort\": 80,\"protocol\":\"tcp\"}],\"memory\":300}]" | jq --raw-output '.taskDefinition.revision')
Value of --container-definitions is a JSON string and YAML parser doesn't like JSON.Even though I have escaped all double quotes using \ char, I think [ and { are throwing it off.
Any ideas?
Hi Hiren,
The issue you're encountering is due to the YAML language spec. ": " (specifically with a space) will turn the command string into a map instead. You can use quotes around the command to ensure it's a string. Though this may still have some issues.
This will fix the parsing issues. But may still fail in your build (I haven't checked it).
- "export TASK_VERSION=$(aws ecs register-task-definition --family MyTask --container-definitions \"[{\"name\":\"MyContainer\",\"image\":\"1234567.dkr.ecr.us-west-1.amazonaws.com/ecs-repository:1.0.13\",\"cpu\":50,\"portMappings\": [{\"hostPort\": 80,\"containerPort\": 80,\"protocol\":\"tcp\"}],\"memory\":300}]\" | jq --raw-output '.taskDefinition.revision')"
Alternatively, you can place all of this into a script file and call it directly from your build (as the command is quite complex, so it may be appropriate to abstract it anyways.
Thanks,
Phil
Thanks. I was able to resolve this by using block comment
- | and put entire command one line below
- |
export TASK_VERSION=$(aws ecs register-task-definition --family EventPlannerTask-STG --container-definitions "[{\"name\":\"EventPlannerContainer\",\"image\":\"$IMAGE_NAME\",\"cpu\":50,\"environment\":[{\"name\":\"ASPNETCORE_ENVIRONMENT\",\"value\":\"Staging\"}],\"portMappings\":[{\"hostPort\":80,\"containerPort\":80,\"protocol\":\"tcp\"}],\"memory\":300}]" | jq --raw-output '.taskDefinition.revision')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.