Reputation: 83
My plan is to create a build project with two sources:
The primary source is the repository of the application I'm building.
A secondary source is a repository containing a generic buildspec.yml and other files like eslint configs.
The reason for that is I want to separate app code from build definition, so I can reuse the same build definition for several apps. The same buildspec.yml and accompanying eslint files are capable of building any of my backend applications.
According to documentation the buildspec path for a build project is a path relative to the root path of primary source.
But what is the correct way of pointing to a buildspec.yml residing in secondary source?
(As far as I know the application code must be the primary source so Codebuild can detect code changes like PRs opened and code push operations.)
(I know that Codebuild allows a S3 path as buildspec path but I don't see how it can help me since my secondary source is a repository.)
Thanks!
Upvotes: 3
Views: 5317
Reputation: 1242
My understanding is that you want ONE buildspec that you can reuse for multiple projects with a similar build. If this is the case, I think you can do this but you need to reverse your primary and secondary sources.
When you create a build project you have to define the buildspec that is going to be used. Your build project is going to use the buildspec from your PRIMARY source. So the SOURCE that has your primary buildspec will need to be your PRIMARY and the project you are going to build will be your SECONDARY.
Then, in your buildspec you can reference the commands pointing to your SECONDARY source using environment variables. In your buildspec, you would reference CODEBUILD_SRC_DIR_sourceIdentier.
I have done this with codepipeline having multiple sources. If you define your output for your secondary source to be called SECONDARY_SOURCE_OUTPUT
Then you would refer to it in your buildspec as $CODEBUILD_SRC_DIR_SECONDARY_SOURCE_OUTPUT/.
Your buildspec exists in your Primary source but you would set your commands would execute from the directory above in your buildspec. Now you can have several similar projects that have the same build pattern use the same buildspec.
In the case below, I use the same buildspec from the project on the left in the source stage, with different projects that can be pulled in as secondary sources.
This link has some information on multiple sources.
Upvotes: 3