1
0

More than 1 year has passed since last update.

Gihtub Actions から実行する JavaScript 内で後続に渡す Output を設定する

Posted at

概要

Github Actions で実行したステップの出力結果を後続に連携したい場合、決められた様式で出力することで対応できます。

      - name: Set color
        id: random-color-generator
        run: echo "SELECTED_COLOR=green" >> $GITHUB_OUTPUT
      - name: Get color
        run: echo "The selected color is ${{ steps.random-color-generator.outputs.SELECTED_COLOR }}"

Actions から実行する JavaScript 内で、出力結果をセットする手順をメモに残す。

手順

  1. @actions/core パッケージをインストール
    • npm install @actions/core
  2. JavaScript 内で core.setOutput を実行する
    const core = require('@actions/core');
    
    core.setOutput('outputKey', 'outputVal');
    
  3. 後続のワークフローで参照する
      - name: echo
        run: |
          echo ${{steps.step_id.outputs.outputKey}}
      - name: if test
        if: steps.step_id.outputs.outputKey != 'SAMPLE_VALUE'
        run: |
          echo "trueの処理"
    

参考情報

https://github.com/actions/toolkit#packages
https://github.com/actions/toolkit/tree/main/packages/core

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