3
0

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.

step間/job間で値の共有【GitHubActions】

Posted at

やりたいこと

GithubActionsワークフローの、step間や、job間で、前に定義した値を次step/jobで使うように共有したい。

やりかた

step間の値の共有

  • $GITHUB_ENVを使用する。
jobs:
    sample-job:
        runs-on: ubuntu-latest
        steps:
            - name: Set value
              run: echo "HOGE=hoge" >> $GITHUB_ENV
            
            - name: Use value
              run: echo "HOGE: ${{ env.HOGE }}"   
              # >> HOGE: hoge     

job間の値の共有

  • step間での共有は$GITHUB_ENVでできていたが、jobが異なると$GITHUB_ENVは使えない。
  • 2022年10月リリースの$GITHUB_OUTPUTを使用する。
    • 今まではset-outputが使用されていたが、こちらは2023年5月31日をもって完全に使用できなくなるとのこと。
    • 公式ブログ
jobs:
    job1:
        runs-on: ubuntu-latest
        outputs:
            hoge: ${{ steps.set_outputs.outputs.hoge }}
            fuga: ${{ steps.set_outputs.outputs.fuga }}
        steps:
            - id: set_outputs
              name: Set outputs
              run: |
                echo "hoge=hoge" >> $GITHUB_OUTPUT
                echo "fuga=fuga" >> $GITHUB_OUTPUT

    job2:
        runs-on: ubuntu-latest
        needs: job1
        steps:
            - name: Use outputs
              run: |
                echo "hoge: ${{ needs.job1.outputs.hoge }}"
                echo "fuga: ${{ needs.job1.outputs.fuga }}"

参考

3
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?