GitHub Actions のジョブ output とは?
ジョブ output はジョブが公開する値で、それを need するジョブが needs コンテキストを通じて読み取れます。
ジョブは分離されているため、ジョブ間でデータを渡すには仕組みが必要です。ジョブ output を使うと、あるジョブが計算したバージョンやイメージタグなどの値を公開し、下流のジョブがそれを利用できます。
概要
ジョブの outputs: マップで宣言される名前付きの値で、ステップ output から取得されます。依存するジョブは needs.<job>.outputs.<name> を通じてそれを読み取ります。
Declaring a job output
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.v.outputs.version }}
steps:
- id: v
run: echo "version=1.2.3" >> "${GITHUB_OUTPUT}"仕組み
あるステップが値を自身のステップ output に書き込み、ジョブがそれをジョブ output にマッピングします。生成元を needs に列挙した下流のジョブが、needs コンテキストからそれを読み取ります。
Consuming it
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- run: echo "Deploying ${{ needs.build.outputs.version }}"使いどころ
- 計算したバージョンやタグを build から deploy へ渡す。
- 下流のジョブを制御するブール値のフラグを共有する。
- 完全な artifact の代わりに短い識別子を受け渡す。
重要な理由
ジョブ output は、バージョン番号、タグ、計算したフラグといった小さな値をジョブ間で渡す正統な方法であり、小さな文字列のために artifact を使わずにパイプラインを DRY に保ちます。
関連する概念
ジョブ output はステップ output と needs キーワードの上に成り立ち、needs コンテキストを通じて読み取られます。
重要なポイント
- ジョブ output は値を依存ジョブに公開します。
- その値はステップ output から取得されます。
needs.<job>.outputs.<name>で読み取ります。
関連ガイド
What Is a Step Output in GitHub Actions?A step output is a named value a step writes to GITHUB_OUTPUT so later steps in the same job can read it via…
What Is the needs Keyword in GitHub Actions?The needs keyword makes one job wait for another to finish, creating a dependency graph and giving access to…
What Is a Context in GitHub Actions?A context in GitHub Actions is a structured object of run data, like github, env, and secrets, that you read…
What Is an Artifact in GitHub Actions?An artifact is a file or set of files a job uploads so they can be downloaded later or shared with other jobs…