Wolf
Wolf

Reputation: 451

AWS Codebuild -- How to read tag on the commit when buildspec.yml is executed?

As the title states, I want to know if there is a tag on the commit SHA that triggered the AWS codebuild.

I have looked at all the Env variables using printenv in my buildspec.yml file and it seems like the only thing AWS codebuild captures from git is the commit hash. I want to know if there's a simple way of getting the tag.

I am pushing the commit and the tag to git in one command:

git push origin <releaseBranch> : <version>

I am looking github's webhook. This is the response I get back from CodeBuild: {"response":"Webhook received and build started: https://us-west-2.console.aws.amazon.com/codebuild/<projectSpecificStuff>/view/new","statusCode":200}

And at the very top of body in the POST from the webhook is: { "ref": "refs/tags/0.0.2", "before": "0000000000000000000000000000000000000000", "after": "6258048d01ca4aa18e7c27dac2d7a51ec5640421", "created": true, "deleted": false, "forced": false, "base_ref": "refs/heads/release-script", ... }

Upvotes: 5

Views: 3051

Answers (1)

Wolf
Wolf

Reputation: 451

The short answer is no as of this writing. AWS Codebuild does not support the webhook for when a tag is created.

My original question was targeted towards creating an easy build system with semantic version attached. I got around the tag issue by creating a branch filter and a bash script.

1) I made my branch filter be build-[0-9]+.[0-9]+.[0-9]+.

2) The I wrote a bash script that:

  • increments the semantic version, triggering a change in the repo.
  • commits the change to my whatever my deploy branch is. (master)
  • creates a new branch with a name that matches the regex above, that also contains the version within it. e.g, build-0.2.11, build-1.2.3, etc.
  • deletes the newly created branch

Just the creation of the remote branch will trigger github to fire the push webhook over to AWS. The webhooks has the name of the branch in it, which you can utilize in your codebuild script. "ref": "refs/heads/build-0.2.11"

Upvotes: 3

Related Questions