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개 답변
0
수락된 답변

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.

전문가
답변함 일 년 전
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.

전문가
답변함 일 년 전
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.

답변함 일 년 전
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

전문가
답변함 일 년 전
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.

답변함 일 년 전
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

답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠