We are using AWS CodeBuild along with GitHub webhooks to trigger a build process. When a PR is created for a branch that starts with a Jira ticket prefix, i.e oscs-278
, we build a new environment with Terraform. When we make commits to the PR it triggers the build process to update that environment.
This flow works well for us, especially since as of February 2021, AWS CodeBuild allows you to set concurrent builds to 1. This is important for us as we should only ever have one deployment at one time, the rest should be queued.
However, our current build process takes up to 15 minutes, if we commit to the branch within this time frame, the project is not being queued if another build is in process.
Is this likely to be an issue with the GitHub webhooks, or something to do with AWS CodeBuild.
From the AWS docs:
The maximum number of builds in a queue is five times the concurrent build limit.
So in theory, I should have 5 in the queue (maximum)
CodeBuild won't queue new builds if the number of currently running builds is at your limit (which is 1). Attempts to start more builds in this condition will fail with an error. The AWS Docs say:
If the build project has a concurrent build limit set, builds return an error if the number of running builds reaches the concurrent build limit for the project. For more information, see Enable concurrent build limit.
This applies for webhooks and attempts to start them manually. The same docs also say:
If the build project does not have a concurrent build limit set, builds are queued if the number of running builds reaches the concurrent build limit for the platform and compute type. The maximum number of builds in a queue is five times the concurrent build limit. For more information, see Quotas for AWS CodeBuild.
That section sort of hints that you can get queuing behavior if you reset your project concurrency limit to a high number (say, 60) and then set the "platform and compute type" concurrency limit to 1, but this isn't possible because that limit isn't user-adjustable (and it would probably apply across all projects).
In short, I don't think you can make CodeBuild queue builds after a configured concurrency limit is reached. A (rather complex) alternative is to do your own locking inside your buildpsec.yml.