AWS CodeBuild has nice integration with different Git repository hosting service providers(like GitHub, BitBucket, even amazon’s own CodeCommit etc). Even using WebHook is pretty easy. You can start a build in CodeBuild for every push, pull, PR created, PR merged etc. But it can be bit tricky when it comes to trigger for every tag push only, as it us not a default event type provided by CodeBuild. You need to add some customized settings to the filter section of the Source for it. Here is how I implemented it step by step.
First you need to enable Rebuild every time a code change is pushed to this repository from the source settings.
You need to change the Event Type to push to trigger the CodeBuild.
I am assuming you want to track tags from any branch. So I have put
* on branch settings:
Finally, I have added the filter in Start a build under this condition. The filter is
If you want to use the Tag number in
buildspec.yml, then use this:
- TAG_NUMBER="$(git describe --tags --abbrev=0)"
But above code won’t work if you are tracking a build which is based on a commit that is not associated a tag or a build that is not triggered by a tag push. To resolve this, you need to increase depth value. You can set it to full but it will increase build time depending of the size of the repository. It is in the Additional configuration section.
IMHO, CodeBuild is a fantastic tool for implementing CI/CD, but documentation lacks some minor details. It might give you subtle hints but you need to dig deeper to find the exact solution. Let us talk more in the comment section if you think this article is missing something. Cheers!!
If you like this article, you can buy me a coffee. Thanks!
Last updated: Nov 06, 2022