5

I have a single repository hosted in AWS CodeCommit with a buildspec.yml in the root that is used by AWS CodeBuild to build from the source.

Is it possible to pass in a variable / read the source (AWS Pipeline arn?) or something similar, such that I can determine in AWS CodeBuild whether to do a Dev, Test or Prod build?

If not, is there another way to accomplish this in AWS CodePipeline that I'm missing?

2 Answers 2

5

AWS CodeBuild supports alternate build specification file. A sample can be found in this AWS blog: https://aws.amazon.com/blogs/devops/create-multiple-builds-from-the-same-source-using-different-aws-codebuild-build-specification-files/

Name your build specification file differently per stage. For example, buildspec_dev.yml, buildspec_qa.yml, etc. Associate each of these with a separate CodeBuild project. After that, you can use the appropriate CodeBuild project within your CodePipeline.

You can also also model these are different stages in your CodePipeline. For example, use the buildspec_dev.yml based project in your build action and then use the buildspec_qa.yml based project in your test action.

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

1 Comment

Thanks! I misread the config page of AWS CodeBuild. It's actually very obvious how to do this... Haha
1

In CodeBuild you can define environmental variables what could be used during the build. So you need to create separate CodeBuild project to each environment, and set the right environmental variables.

In case if you are using CodePipeline as well, then I assume that there are different branches created for different environments. So you can define a hook for commits on these branches, and the CodePipeline will call the right CodeBuild 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.