gpt4 book ai didi

perl - 在 GitHub Action 的新作业中使用上一作业的输出

转载 作者:行者123 更新时间:2023-12-02 00:49:29 27 4
gpt4 key购买 nike

出于(主要)教学原因,我尝试在 GitHub 操作中运行此工作流程:

name: "We 🎔 Perl"
on:
issues:
types: [opened, edited, milestoned]

jobs:
seasonal_greetings:
runs-on: windows-latest
steps:
- name: Maybe greet
id: maybe-greet
env:
HEY: "Hey you!"
GREETING: "Merry Xmas to you too!"
BODY: ${{ github.event.issue.body }}
run: |
$output=(perl -e 'print ($ENV{BODY} =~ /Merry/)?$ENV{GREETING}:$ENV{HEY};')
Write-Output "::set-output name=GREET::$output"
produce_comment:
name: Respond to issue
runs-on: ubuntu-latest
steps:
- name: Dump job context
env:
JOB_CONTEXT: ${{ jobs.maybe-greet.steps.id }}
run: echo "$JOB_CONTEXT"

我需要两个不同的作业,因为它们使用不同的上下文(操作系统),但我需要将第一个作业中的步骤的输出获取到第二个作业。我正在尝试使用发现的 jobs 上下文的几种组合 here但似乎没有任何办法可以做到这一点。显然,jobs 只是一个 YAML 变量的名称,它没有真正的上下文,而上下文 job 只包含成功或失败。有什么想法吗?

最佳答案

检查 2020 年 4 月的“GitHub Actions: New workflow features ”,这可能对您的情况有所帮助(引用以前作业的步骤输出)

Job outputs

You can specify a set of outputs that you want to pass to subsequent jobs and then access those values from your needs context.

参见documentation :

jobs.<jobs_id>.outputs

A map of outputs for a job.

Job outputs are available to all downstream jobs that depend on this job.
For more information on defining job dependencies, see jobs.<job_id>.needs.

Job outputs are strings, and job outputs containing expressions are evaluated on the runner at the end of each job. Outputs containing secrets are redacted on the runner and not sent to GitHub Actions.

To use job outputs in a dependent job, you can use the needs context.
For more information, see "Context and expression syntax for GitHub Actions."

To use job outputs in a dependent job, you can use the needs context.

Example

jobs:
job1:
runs-on: ubuntu-latest
# Map a step output to a job output
outputs:
output1: ${{ steps.step1.outputs.test }}
output2: ${{ steps.step2.outputs.test }}
steps:
- id: step1
run: echo "test=hello" >> $GITHUB_OUTPUT
- id: step2
run: echo "test=world" >> $GITHUB_OUTPUT
job2:
runs-on: ubuntu-latest
needs: job1
steps:
- run: echo ${{needs.job1.outputs.output1}} ${{needs.job1.outputs.output2}}

注意 $GITHUB_OUTPUT 的使用,而不是 older ::set-output now (Oct. 2022) deprecated .

To avoid untrusted logged data to use set-state and set-output workflow commands without the intention of the workflow author we have introduced a new set of environment files to manage state and output.

<小时/>

Jesse Adelman添加the comments :

This seems to not work well for anything beyond a static string.
How, for example, would I take a multiline text output of step (say, I'm running a pytest or similar) and use that output in another job?

关于perl - 在 GitHub Action 的新作业中使用上一作业的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59175332/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com