How to build a project combining code from two repositories

0

Hello, I have an application whose code is split between two repositories, and I would like to use code pipeline to combine them. The first one contains the actual code and needs to be built. The second contains a .env file with parameters needed to run the build. It also needs to be deployed to Beanstalk for the application to run properly.

What I tried so far:

  • I defined a source that is triggered by commits to repo A, and outputs the artifacts to SourceArtifacts.
  • Then I defined another source that is triggered by commits to repo B, and outputs the artifacts to SourceArtifacts2.
  • Then I defined a Build stage that uses SourceArtifacts and SourceArtifacts2 as Input Artifacts, runs the build command and outputs to BuildOutput.
  • Finally I defined a deploy stage that gets the code from BuildOutput and deploy to Beanstalk.

My problem is that when the build runs it can't access the values in the .env file, so it fails.

Also the .env file from repo B is not deployed.

I was wordering if there's any specific workaround to achieve this.

thanks M

6 Answers
0
Accepted Answer

Yes you're right, defining a CodeCommit repo source in the console sets up the EventBridge Rule as I described anyway.

What's more relevant is that you'll get only one of SourceArtifacts or SourceArtifacts2 populated depending on which repo triggered the build. So you can't rely on either and may need to clone both repos as part of your CodeBuild setup, then access the files you need from these clones.

EXPERT
answered a year ago
0

Do you want to actually trigger a build when repo B changes or just when repo A changes? If the latter then maybe an option is to just have repo A as a source, and have a CodeBuild step where you clone repo B and access the files you need.

EXPERT
answered a year ago
0

The ideal would be to trigger a build both when one of the two changes: I need a new build when the code changes but also when a config param changes. But the important thing would be to have the build stage (Codebuilder) able "to see" both repos to actually build.

answered a year ago
0

Ok then I would have repo A as the source for your pipeline, and create an EventBridge rule on events from repo B that triggers your pipeline when repo B changes.

https://docs.aws.amazon.com/codecommit/latest/userguide/monitoring-events.html

https://docs.aws.amazon.com/codeartifact/latest/ug/configure-service-events-codepipeline.html

EXPERT
answered a year ago
0

I think this is not necessary. To trigger the pipeline I can just define two sources, and I did it. My problem here is in the builder itself.

What I am trying to do is to have Codebuilder to take the code from repoA, then the code from repoB, put them together and then run "npm run build" as defined in the buildspec file.

What is happening is that Codebuilder triggers the run but can't see the values from the .ini file in repoB, so it fails.

answered a year ago
0

OK thanks for that. I guess I am going to add the .env to the repo, I can't see any other flexible solution for my use case.

thanks M

answered a year 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