1

I am running an AWS CodePipeline building Angular project and shifting it to a S3-Bucket. Simplified buildspec looks like that:

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 10
  pre_build:
    commands:
      - echo Building staging profile
  build:
    commands:
      - echo Entered the build phase for https://s3.console.aws.amazon.com/s3/buckets/<mycoolbucket> ...
      - cd db
      - npm install
      # Build in production mode
      - npm run nx -- build db-app-desktop --prod --outputHashing=all
      - echo successfully finished build phase...
  post_build:
    commands:
      - echo Entered the post_build phase...
      - aws s3 sync dist/apps/db-app-desktop s3://<mycoolbucket> --delete;
      - echo Successfully finished post_build phase

This works well for a successful build. But if the project has any errors, such that the build fails, CodeBuild is still showing success status. In the Codebuild log, the build ends with an Error message like that:

    Error: libs/db-app-desktop/*/*/details.component.ts:1700:13 - error TS0000: Build failes by project error.

[... details ...]

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! db@0.9.2-3.0 nx: `nx "build" "db-app-desktop" "--prod" "--outputHashing=all"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the db@0.9.2-3.0 nx script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-09-23T13_55_48_300Z-debug.log

[Container] 2021/09/23 13:55:48 Running command echo successfully finished build phase...
successfully finished build phase...

[Container] 2021/09/23 13:55:48 Phase complete: BUILD State: SUCCEEDED

But the AWS console shows green lights, there is no fail notification sent. The application is not changed and remains the one from last successful build.

How does Codebuild know that the executed build fails? We have a Java Backend, where an error in build phase immediately sets the builds/codepipelines state to FAILED, which would be the apreciated behavior here as well.

4

0 回答 0