Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have multiple CodeBuild buildspec files in different directories?

I have a large monorepo with many projects in it. I want to have many build jobs, each using a buildspec in the relevant tree in the repo.

For example, I have a lambda function called Email, and a java application called Web. The source trees for each are siblings, and I want to put a buildspec in each and have different jobs use the different buildspec.yml files.

I can't find a way to make this work, as the name of the buildspec file specified in the job must be at the root of the repo (it's a git repo).

like image 947
Gizmo Gadget Guy Avatar asked Aug 16 '17 21:08

Gizmo Gadget Guy


People also ask

Where do I put Buildspec file?

Store a buildspec file somewhere other than the root of your source directory, such as config/buildspec. yml or in an S3 bucket. The S3 bucket must be in the same AWS Region as your build project. Specify the buildspec file using its ARN (for example, arn:aws:s3:::my-codebuild-sample2/buildspec.

What is contained in an AWS CodeBuild Buildspec file?

A buildspec is a collection of build commands and related settings, in YAML format, that CodeBuild uses to run a build. Without a build spec, CodeBuild cannot successfully convert your build input into build output or locate the build output artifact in the build environment to upload to your output bucket.

What Shell does AWS CodeBuild use?

AWS CodeBuild now supports the bash and CMD shell environments for executing commands and scripts. The bash shell is available for machines hosting versions of Amazon Linux or Ubuntu, and the CMD shell is available on machines hosting versions of Microsoft Windows Server.

What is artifact in AWS CodeBuild?

Artifacts is a property of the AWS::CodeBuild::Project resource that specifies output settings for artifacts generated by an AWS CodeBuild build.


3 Answers

You can specify an alternate buildspec location in the buildspec or buildspecOverride parameter to Create/UpdateProject or StartBuild.

The buildspec path is relative to the root of your Git repo. So you can use, e.g., ./subdir/buildspec.yml

You can find the documentation here: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-name-storage

like image 189
Unsigned Avatar answered Oct 05 '22 22:10

Unsigned


There's now a way to change the buildspec path of a CodeBuild project via the console. Edit a project (console url is https://[region-name].console.aws.amazon.com/codebuild/home?region=[region-name]#/projects) and under "Environment: How to build" there's a parameter called "Buildspec name". Set that to the path of the buildspec.yml file relative to the root directory.

like image 28
skeller88 Avatar answered Oct 05 '22 23:10

skeller88


This is now possible when using the console as well, but they don't make it easy to find.

  • When you are first configuring the build, the console will not give you an option to specify a custom buildspec file name / location. Instead, in the "Environment: How to build" section choose the Use the buildspec.yml in the source code root directory option as normal and save the build project.

FirstConsoleEdit

  • Then you will be able to go back and re-edit the project. Once you do so, you will see that the "Environment: How to build" section now has a link called "Update build specification".

CodeBuildReEdit

  • Click the "Update build specification" link and a section will open up that includes a "Buildspec Name" input where you can enter the custom name of / path to your buildspec file.

CodeBuildReEditSuccess

like image 43
lemmingworks Avatar answered Oct 05 '22 22:10

lemmingworks