github - Github Actions/workflow_run/outputs
问题描述
我有一个工作流build
,其输出存储在 docker 注册表中,具体取决于其结果,然后,我想运行e2e test
.
我知道我可以使用workflow_run
,但不清楚如何将输出传递给依赖的工作流。
on:
workflow_run:
workflows: ["Build"]
types: [completed]
我应该能够获取IMAGE_URL
输出并对那个特定的人工制品运行测试。
- 如何设置工作流输出
- 如何读取工作流输出
当前的解决方法是使用workflow_dispatch
,但它的缺点是没有被列为 PR 检查。
解决方案
您可以将要传递的变量和值写入文件,并将其作为工件上传到触发工作流中。
在触发的工作流中,下载触发工作流运行的工件。然后解析文件以获取您的变量。
触发工作流
[...]
name: Build
jobs:
aJob:
name: A job
runs-on: ubuntu-latest
steps:
- run: echo "aVariable,aValue" > vars.csv
- uses: actions/upload-artifact@v2
with:
name: variables
path: vars.csv
触发的工作流
(来自其他工作流的工件不能与操作一起下载download-artifact
)
on:
workflow_run:
workflows: ["Build"]
types: [completed]
jobs:
aJob:
name: A job
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v4
id: get-artifact-id
with:
result-encoding: string
script: |
const result = await octokit.request('GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts', {
owner: '${{github.repository_owner}}',
repo: '${{github.event.repository.name}}',
run_id: ${{github.event.workflow_run.id}}
})
# assumes the variables artifact is the only one in this workflow
return result.data.artifacts[0].artifact_id
- name: Get result
run: |
echo "${{steps.get-artifact-id.outputs.result}}"
curl -L -H "Authorization: token ${{github.token}}" \
-H "Accept: application/vnd.github.v3+json" \
-O variables.zip \
https://api.github.com/repos/${{github.repository}}/actions/artifacts/${{steps.get-artifact-id.outputs.result}}/zip
unzip variables.zip
# parse variables from variables.csv and set them
推荐阅读
- css - 如何创建一个有 5 个块的 CSS 网格(第 1 行 2 个,第 2 行 3 个)
- python - 如何从 mongodb 获取所有数组元素,而不是为 python 创建 piepline 的第一个元素
- java - 致命错误:每次我启动 Android Studio 时都会出现 SIGSEGV
- android - 关闭应用程序时安排任务(日期到来时的通知)
- python - 熊猫:按日期移动一列但保留用户
- flutter - 返回类型“bool”不是闭包上下文所要求的“KeyEventResult”
- java - 如何在java中排除完全空的对象形式的JSON响应
- python - 将json转换为excel时在python中出现类型错误
- jmeter - 如何通过 beanshell 采样器使用 JDBC 处理在 Oracle 上运行相同循环的多个用户
- python - Numba:选择数组的 N 维子集