0

Let's imagine that we have one CodePipeline with 2 stages in the following fashion:

new codepipeline.Pipeline(this, name + "Pipeline", {
    pipelineName: this.projectName + "-" + name,
    crossAccountKeys: false,
    stages: [{
        stageName: 'Source',
        actions: [codeCommitSourceAction]
    },{
        stageName: 'Build',
        actions: [buildAction]
    }]
});

Here the Source stage is where we pull the changes from the repository and the Build one is a CodeBuild project which has the following actions in the buildspec file:

  1. Install the dependencies (npm i).
  2. Run the tests (npm run test).
  3. Pack the project (npm run pack).
  4. Update/deploy lambda function (aws lambda update-function-code).

In general it does what it supposed to do, however, if the build fails, the only way to find out, which part has failed, is to look to the logs. I would like that it is seen straight from CodePipeline. In this case CodePipeline must have more stages which correlate with each action from CodeBuild. Based on my experience I can do it if for every stage I provide different CodeBuild project.

Question: can I provide same CodeBuild project to the different CodePipeline stages so, that it will execute only part of buildspec file (for example, only running the tests)?

2 Answers 2

1

You can have your buildspec.yml perform different actions based on environment variables. You can then pass different environment variables to CodeBuildAction with environmentVariables.

new codepipeline_actions.CodeBuildAction({
  actionName: 'Build',
  project: buildProject,
  input: sourceInput,
  runOrder: 1,
  environmentVariables: {
    STEP: { value: 'test' }
  }
}),

And then check STEP environment variable in buildspec.yml.

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

1 Comment

yes, that worked, thanks! In case somebody searched how to use environment variable in JSON format, it is here: stackoverflow.com/questions/62881332/…
0

Question: can I provide same CodeBuild project to the different CodePipeline stages so, that it will execute only part of buildspec file (for example, only running the tests)?

No, I don't think that is possible.

What you can do however, is to have different buildspecs.yml file called at different stages of your pipeline.

For example, you could have a Codepipeline stage called Init which will call the builspec_init.yml of your project. If that succeed, you could have a following state Apply calling the buildspec_apply.yml file of your project.

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.