I\'m setup AWS CodeBuild to build automatically from GitHub. Other CI services provide an environment variable for the branch, but I can\'t find one for AWS CodeBuild. There is
It's now possible to obtain this information directly from CodeBuild environmental variables:
CODEBUILD_WEBHOOK_BASE_REF
: The base reference name of the webhook event that triggers the current build. For a pull request, this is the branch reference.CODEBUILD_WEBHOOK_HEAD_REF
: The head reference name of the webhook event that triggers the current build. It can be a branch reference or a tag reference.CODEBUILD_WEBHOOK_TRIGGER
: Shows the webhook event that triggered the build. This variable is available only for builds triggered by a webhook. The value is parsed from the payload sent to CodeBuild by Github, Github Enterprise, or Bitbucket. The value's format depends on what type of event triggered the build.
- For builds triggered by a pull request, it is pr/pull-request-number.
- For builds triggered by creating a new branch or pushing a commit to a branch, it is branch/branch-name.
- For builds triggered by a pushing a tag to a repository, it is tag/tag-name.