0

I am trying to store the result of an aws command into a variable in CodeBuild (Ubuntu/Bash).

The command is:

aws codepipeline get-pipeline-state --region ${AWS_DEFAULT_REGION} --name ${CODEBUILD_INITIATOR#codepipeline/} --query 'stageStates[?actionStates[?latestExecution.externalExecutionId==`'${CODEBUILD_BUILD_ID}'`]].latestExecution.pipelineExecutionId' --output text

I have tried several escaping techniques, but various error messages, including:

Bad value for --query 'stageStates[?actionStates[?latestExecution.externalExecutionId=='single3-docker:f3f7b493-643c-489c-ab68-c613f6477d48']].latestExecution.pipelineExecutionId': Bad jmespath expression: Unknown token '-':'stageStates[?actionStates[?latestExecution.externalExecutionId=='single3-docker:f3f7b493-643c-489c-ab68-c613f6477d48']].latestExecution.pipelineExecutionId'

This is how I escaped it:

EXECUTION_ID=`aws codepipeline get-pipeline-state --region ${AWS_DEFAULT_REGION} --name ${CODEBUILD_INITIATOR#codepipeline/} --query \'stageStates[?actionStates[?latestExecution.externalExecutionId==\'${CODEBUILD_BUILD_ID}\']].latestExecution.pipelineExecutionId\' --output text`

When I run the command raw, I get the expected result echoed to the log just fine.

How can I run this command and properly escape to assign the result to a variable?

Tim Bassett
  • 1,064
  • 1
  • 9
  • 21

0 Answers0