copilot-cli: Pipeline fails in CodeBuild POST_BUILD with `COMMAND_EXECUTION_ERROR Message: Error while executing command: for env in $pl_envs;`

Hello, I’m using Copilot in windows for a dotnet project. I have a pipeline that that fails in CodeBuild on the POST_BUILD phase with the following error:

image

Build logs shows this error: [Container] 2022/05/11 04:20:06 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: for env in $pl_envs; do tag=$(sed 's/:/-/g' <<<"${CODEBUILD_BUILD_ID##*:}-${env}" | rev | cut -c 1-128 | rev) for svc in $svcs; do ./copilot-linux svc package -n $svc -e $env --output-dir './infrastructure' --tag $tag --upload-assets; if [ $? -ne 0 ]; then echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2; exit 1; fi done; for job in $jobs; do ./copilot-linux job package -n $job -e $env --output-dir './infrastructure' --tag $tag --upload-assets; if [ $? -ne 0 ]; then echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2; exit 1; fi done; done; . Reason: exit status 1

It refers to this line in buildspec.yml: image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I am experiencing a similar error when I use the Ubuntu aws/codebuild/standard:6.0 image in CodeBuild. Here is an extract from my logs:

[Container] 2022/08/20 00:11:31 Running command for env in $pl_envs; do
  tag=$(sed 's/:/-/g' <<<"${CODEBUILD_BUILD_ID##*:}-${env}" | rev | cut -c 1-128 | rev)
  for svc in $svcs; do
  ./copilot-linux svc package -n $svc -e $env --output-dir './infrastructure' --tag $tag --upload-assets;
  if [ $? -ne 0 ]; then
    echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2;
    exit 1;
  fi
  done;
  for job in $jobs; do
  ./copilot-linux job package -n $job -e $env --output-dir './infrastructure' --tag $tag --upload-assets;
  if [ $? -ne 0 ]; then
    echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2;
    exit 1;
  fi
  done;
done;
/codebuild/output/tmp/script.sh: 5: Syntax error: redirection unexpected
[Container] 2022/08/20 00:11:31 Command did not exit successfully for env in $pl_envs; do

I could not 100% confirm this but my hypothesis is that the commands are running in sh instead of bash and thus the <<< in the second line does not parse.

Since the generated buildspec is already using Ruby in other parts of the build I replaced it with a more portable version and it works correctly for me now.

tag=$(ruby -e 'puts ARGV[0].split(":").last[0..128]' "${CODEBUILD_BUILD_ID}-${env}")

No rush! Hope you’re feeling better!

Thanks! Can you also paste here the manifests for the workloads (services/jobs) that you’re attempting to deploy with this pipeline?

Hi, @ryancody! Would you mind copy-pasting your manifest here? Thanks!