github-actions - 如何在工作流中使用 Github 操作的输出?
问题描述
让我们以Github 文档中的这个示例复合操作为例:
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
在调用此操作的外部工作流中使用该特定输出?我尝试了以下代码段,但目前似乎工作流程无法从操作中读取输出变量,因为它只是空的 - '输出 - '
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 }}'
})
解决方案
看来我的尝试是正确的,除了一个细节:
代替:
${{ steps.hello-world.outputs.random-number.value }}
应该在没有以下内容的情况下引用它.value
:
${{ steps.hello-world.outputs.random-number}}
现在它起作用了。
推荐阅读
- .net - 使用 httpwebrequest 调用 ibm watson discovery adddocument api
- php - Campaign Monitor API - 自定义表单
- xaml - UWP 根据屏幕大小调整控件布局/位置
- java - Java如何管理夏令时?
- sql - 对象“ATM_BRANCH”没有文本
- android - 应用程序被 E/com.facebook.internal.AttributionIdentifiers 卡住
- ios - Cordova 访问没有应用程序 ID 的应用程序文件或访问以前的 ID 文件
- python - 在 django 模型中发送和接收信号
- javascript - for...in 与数组输出字符串而不是数字
- python - 生成没有 NaN 值的新 DataFrame