CodeBuild 显示成功;但是,使用 Packer 时应该显示 FAILED

CodeBuild shows SUCCEEDED; however, it should be saying FAILED when using Packer

我 运行 遇到一个问题,我知道这与我的 buildspec.yml 文件有关:

phases:
  install:
    runtime-versions:
      python: 3.8
  pre_build:
    commands:
      - echo "Installing Packer"
      - curl -o packer.zip https://releases.hashicorp.com/packer/1.7.2/packer_1.7.2_linux_amd64.zip && unzip packer.zip
      - echo "Validating Packer template"
      - ./packer validate pipeline/build/${FUNCTION}-build.json
  build:
    commands:
      - ./packer build -color=false pipeline/build/${FUNCTION}-build.json | tee build.log
  post_build:
    commands:
      # Get the ARN of our Lambda notifier
      - SLACK_ARN=$(aws cloudformation list-exports | jq -r '.["Exports"][] | select(.Name == "notify_slack_arn") | .Value')
      # Send a Slack notification
      - |
        if [ "${CODEBUILD_BUILD_SUCCEEDING}" -eq 1 ]
        then
          aws lambda invoke --cli-binary-format raw-in-base64-out --function-name ${SLACK_ARN} --payload "{ \"LambdaInvokeEvent\": { \"message\": \"Daily AMI Build for ${FUNCTION} SUCCESSFUL!\", \"slack_url\": \"${SLACK_URL}\" } }" slack_output.log
        else
          aws lambda invoke --cli-binary-format raw-in-base64-out --function-name ${SLACK_ARN} --payload "{ \"LambdaInvokeEvent\": { \"message\": \"Daily AMI Build for ${FUNCTION} FAILED!\", \"slack_url\": \"${SLACK_URL}\" } }" slack_output.log
        fi
      - echo "Build completed on $(date)"
artifacts:
  files:
    - "**/*"
  discard-paths: no

因此,根据我在 CodeBuild 中构建的代码,会发生以下情况:

尽管它失败了,但 CodeBuild 说成功了,这让我抓狂!它应该失败并发出失败通知。这是否与我的 buildspec.yml 文件或我的 bash 脚本 运行 有关?谢谢!

我认为这是因为您的 | tee build.log。 packer 失败,但 tee 工作,因此这是执行的最后一个命令,构建阶段成功。