3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CodeBuildでブランチ名を取得する

Last updated at Posted at 2020-12-10

概要

  • AWS CodeBuildでどのブランチをビルドしているのか取得したい

やりかた

CodeBuildのWebHookでGitHubのプルリクをトリガーにしている場合、ビルド環境変数 $CODEBUILD_WEBHOOK_BASE_REF を用いることでマージ先のブランチを取得できます。

このとき、git branch の形式ではなく、 git symbolic-ref HEAD の形式で取得されるので、testなどで切り分けるときは注意が必要です。

buildspec.yml
version: 0.2
phases:
  pre_build:
    commands:
      # Git Branch を取得
      # 
      - >
        if [ "$CODEBUILD_WEBHOOK_BASE_REF" = "refs/heads/main" ];then
          DEPLOY_ENV="prd"
        else
          DEPLOY_ENV="stg"
        fi

参考

Git - Gitの参照

ビルド環境の環境変数 - AWS CodeBuild

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?