2

Folks, Have been trying to figure out the correct way to fire of a CodeBuild project which either produces the artifact after compiling and running jasmine tests, or fails and stops the CodePipeline from proceeding with deployment.

If my buildspec.yml looks like:

version: 0.1

phases:
  install:
    commands:
      - echo Installing... Running npm install
      - npm install
  pre_build:
    commands:
      - echo pre_build...
  build:
    commands:
      - echo Testing... Running npm test
      - npm test
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - '**/*'

How should I fail out of the npm test phase? If any of the jasmine tests fail during npm test, will the artifact still be produced?

Another thought I have is to have the following occur if any of the tests fail:

    var params = {
        jobId: jobId,
        failureDetails: {
            message: JSON.stringify(message),
            type: 'JobFailed',
            externalExecutionId: context.invokeid
        }
    };
    codepipeline.putJobFailureResult(params, function(err, data) {
        ...
    });

or send a stop signal to CodeBuild?

var params = {
  id: 'STRING_VALUE' /* required */
};
codebuild.stopBuild(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

Or how do I terminate the build to not produce the artifact? Maybe I got this wrong, and it should be a Lambda function that kicks off the unit tests. I am not sure if Lambda is ideal for this, as I can imagine some services take a while to finish the unit tests

Thanks!

1 Answer 1

3

In case anyone stumbles upon this, both ways will work. AWS CodeBuild will fail on any non-zero exit status code. Thus, any tests that fail will cause the pipeline to fail.

Same can be done with lambda

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.