Milk
Milk

Reputation: 2655

How to build to Dev/Test/Prod with AWS CodeBuild

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?

Upvotes: 5

Views: 3798

Answers (2)

Ernie Jay
Ernie Jay

Reputation: 161

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.

Upvotes: 1

Subin Mathew
Subin Mathew

Reputation: 2545

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.

Upvotes: 5

Related Questions