Use same CodeBuild project for multiple GitHub repositories


I have a GitHub repository for which I have successfully created a CodeBuild project that gets run automatically on pull request events. I now have a scenario in which I want to extend that CodeBuild project to multiple GitHub repositories. I updated the repositories to have the same my_buildspec.yml file and also updated the "Sources" section of the CodeBuild project to point to the new GitHub repositories. But, the builds are only getting triggered for events on the primary source and not on the secondary source. All the GitHub repositories are using the same buildspec file with the same name and content and in the default branch.

How can I ensure that the same CodeBuild project gets triggered for events on secondary source GitHub repositories? I know I can create multiple CodeBuild projects (one for each GitHub repository) but is there a way to use the same CodeBuild project for multiple GitHub repositories?

asked 3 years ago2599 views
1 Answer
Accepted Answer

Hey samkit-juvoxa

Thank you for your question on how to dynamically update your project using Codebuild with multiple GitHub Repositories.

I have replicated your use case in my own environment using AWS CodePipeline and configured it using two GitHub repositories as sources which dynamically triggered Codebuild. Below are the steps I took.

Currently this feature update your Build Project using CodeBuild with multiple GitHub resources to automatically trigger CodeBuild isn't an available feature that CodeBuild provides. However Integrating your CodeBuild project into CodePipeline with fix this problem.

Here you can find how CodePipeline integrates with CodeBuild to use multiple input sources as outlined in your use case [1] .

  1. First create two separate GitHub repositories in an account with different source code in each.

  2. Then configure a CodeBuild project with a name and a buildspec that outputs the source code in a giving directory [2].

  3. Next continue to the CodePipeline Console and create a pipeline . Configure the source page and select GitHub as the source provider, which prompted a sign in, in order to authorize application access to the account. When the account is authorized this may you chose your GitHub repository for the source location for your pipeline, along with the branch . [3]

  4. Then configure the Build section , you should chose CodeBuild and from here chose the Build Project you created in step 2.

  5. You should chose to skip the deploy stage, as this step was is necessary for the pipeline.

  6. When the build is complete, you can edit the source section of the Pipeline, to add a “new stage”. Here you will prompted to sign into GitHub. When authorized choose add source and pick the second repository you've created and save.

When commits are made to either of the GitHub repositories they will automatically trigger the Pipeline which your CodeBuild project is associated to.

Please feel free to reach out to me with any questions or concerns .



answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions