【问题标题】:How can I use a Github action's output in a workflow?如何在工作流中使用 Github 操作的输出?
【发布时间】:2021-07-20 20:24:45
【问题描述】:

让我们以 Github 文档中的 composite 动作为例:

name: 'Hello World'
description: 'Greet someone'
inputs:
  who-to-greet:  # id of input
    description: 'Who to greet'
    required: true
    default: 'World'
outputs:
  random-number:
    description: "Random number"
    value: ${{ steps.random-number-generator.outputs.random-id }}
runs:
  using: "composite"
  steps:
    - run: echo Hello ${{ inputs.who-to-greet }}.
      shell: bash
    - id: random-number-generator
      run: echo "::set-output name=random-id::$(echo $RANDOM)"
      shell: bash
    - run: ${{ github.action_path }}/goodbye.sh
      shell: bash

我们如何在调用此操作的外部工作流程中使用该特定输出 random-number?我尝试了以下 sn-p 但目前似乎工作流无法从操作中读取输出变量,因为它只是空的 - '输出 - '


jobs:
  test-job:
    runs-on: self-hosted
    steps:
      - name: Call Hello World 
        id: hello-world
        uses: actions/hello-world-action@v1
      - name: Comment
        if: ${{ github.event_name == 'pull_request' }}
        uses: actions/github-script@v3
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            github.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: 'Output - ${{ steps.hello-world.outputs.random-number.value }}'
            })

【问题讨论】:

    标签: github-actions building-github-actions


    【解决方案1】:

    看来我的尝试是正确的,除了一个细节:

    代替:

    ${{ steps.hello-world.outputs.random-number.value }}
    

    应该在没有.value的情况下引用它:

    ${{ steps.hello-world.outputs.random-number}}
    

    现在可以了。

    【讨论】:

    • 感谢您回来回答您自己的问题。诸如此类的事情可以帮助很多人。
    • 不客气@AmitDas!
    猜你喜欢
    • 2020-03-15
    • 2022-08-23
    • 2021-04-17
    • 2022-06-12
    • 2021-07-25
    • 2023-01-05
    • 2021-07-29
    • 2021-11-09
    • 1970-01-01
    相关资源
    最近更新 更多