I'm trying to use the AWS CLI to invalidate my CloudFront distribution. This consists of two commands, one to create the invalidation and then one to wait for it to complete.
To do this, I need to capture the invalidation ID that AWS sends back to me and pass it to the second command. After lots of Googling I have settled on the below script. Whilst not pretty, it serves it's purpose.
pipelines:
branches:
Stage/development:
- step:
name: Invalidate
image: cgswong/aws:aws
script:
- for /f usebackq %F in (`aws cloudfront create-invalidation --distribution-id "##############" --paths /* --query "Invalidation.Id"`) do aws cloudfront wait invalidation-completed --distribution-id "##############" --id %F
The command I've written works perfectly on my machine (Windows 10) but when it's run as part of the Pipeline, I get the following error:
bash: /opt/atlassian/pipelines/agent/tmp/bashScript6992979577238911185.sh: line 5: syntax error near unexpected token `usebackq'
I've tried putting usebackq in quotes but that didn't help - same error.
Could someone help with this please or offer another solution?