0
2

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 1 year has passed since last update.

ブランチによって処理を変える【GitHubActions】

Posted at

やりたいこと

GitHubActionsのワークフローにおいて、push先ブランチによって、処理を変更する。

実装方法

push先が、devブランチのときとmainブランチのときで、設定する環境変数の値を変える例を実装する。
以下のように、stepのif句で github.ref_name で条件を書いてあげればOK。

name: sample-workflow

on:
  push:
    branches: [dev, main]

jobs:
  sample-job:
    runs-on: ubuntu-latest

    steps:
      - name: Set dev value
        if: ${{ github.ref_name == 'dev' }}
        run: |
          echo "ENV=dev" >> $GITHUB_ENV

      - name: Set prd value
        if: ${{ github.ref_name == 'main' }}
        run: |
          echo "ENV=prd" >> $GITHUB_ENV
0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?