0

I am using AWS code pipeline, how to configure it for different branches? I have two branches master and dev and need different configurations (appspec.yml) was not able to find any good documentation related to this. Could someone help on this?

7
  • 1
    Have a build stage which creates correct appspec.yml based on your branch before deployment stage. Commented Feb 21, 2022 at 9:34
  • Hey @Marcin, ya seems like that is the only solution thanks. Found same solution here also stackoverflow.com/a/68507946/12912841 Commented Feb 21, 2022 at 10:02
  • I would use two pipelines. How can you tell without detailed inspection which has been run thru the pipeline. We have a pipeline per branch. Commented Feb 21, 2022 at 16:43
  • @TimBassett, even I have same use case (master & develop branch) and have created two pipelines, but there can be only one appspec.yml file so was looking how to provide different appspec config for each branch Commented Feb 21, 2022 at 16:55
  • 1
    I'm not going to be able to provide you with a "canned solution", but here's some ideas. I haven't use CodeDeploy, but you can set environment variables in earlier pipeline actions and export them from your buildspec and then ingest them in later actions. You need to use variable namespace for the action to export it and then you use that namespace in your pipeline later. Also, we were copying one of two app.configs to a final.app.config during a codebuild and putting it into the artifact that way. You could do that, have two separate configs and decide which to copy to the artifact. Commented Feb 21, 2022 at 17:25

1 Answer 1

1

I will like to answer this, as I was in the same situation and mindest. Most people compare the Jenkins strategies and try to apply them in the code pipeline. (Keeping the branch variable)

Understanding the two systems. Code Pipeline wasn't designed to handle such complex configurations. There is a way to do it (but the complexity defeats the purpose of doing it). It requires a way complex understanding of the system, which the devs in the initial phase of exploring the service might not have.

Here is the article explaining how you can create a multi-branch strategy. https://aws.amazon.com/blogs/devops/multi-branch-codepipeline-strategy-with-event-driven-architecture/

I understand it now, but when I was just starting, it was a nightmare.

The easiest approach will be to have two separate buildspec.yml with two code build applications and change the appspec.yml dynamically while exporting artefacts in code build. Code deploy will take care of deployment configurations based on appsepc.yml.

If such reconfigurability is an issue for you, I'll recommend exploring Jenkins & other options.

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

1 Comment

Thanks for the link and Ya I am using the 2nd method now to handle different branches.

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.