首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在工作流中使用Github操作的输出?

如何在工作流中使用Github操作的输出?
EN

Stack Overflow用户
提问于 2021-04-27 13:26:17
回答 1查看 9.2K关注 0票数 17

让我们以这个例子为例,在Github的文档中找到复合操作:

代码语言:javascript
复制
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?我尝试了下面的代码片段,但目前似乎工作流无法从操作中读取输出变量,因为它只是空的-“输出-”。

代码语言:javascript
复制
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 }}'
            })
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-27 13:42:47

除了一个细节之外,我的尝试似乎是正确的:

而不是:

代码语言:javascript
复制
${{ steps.hello-world.outputs.random-number.value }}

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

代码语言:javascript
复制
${{ steps.hello-world.outputs.random-number}}

现在起作用了。

票数 30
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67283976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档