获取上一步骤中的GitHub操作输出。

huangapple go评论67阅读模式
英文:

Get Github action output from previous step

问题

I am building my own Github-actions repository.
我正在构建我的自定义Github Actions仓库。

I am trying to use the output of an action in the following step, but I could not manage to do so.
我试图在下一步中使用操作的输出,但我无法成功。

This is a minimal example with what I want to do:
这是一个我想要做的最小示例:

I have an action that does some stuff and stores an output value (boolean for instance). The minimum action.yml would be like this:
我有一个操作,它执行一些操作并存储一个输出值(例如布尔值)。最小的action.yml如下所示:

# action_with_output/action.yml
name: action_with_output

outputs:
  out:
    description: 'Some output'

runs:
  using: composite
  steps:
    - name: action with output step
      shell: bash
      run: echo "out=true" >> $GITHUB_OUTPUT

Then, in my workflow I want to use such output called out. Like this:
然后,在我的工作流中,我想要使用名为 out 的输出,就像这样:

# .github/workflows/my_workflow.yml
...

workflow_name:
  runs-on: ubuntu-22.04
  steps:

  - name: Sync repository
    uses: actions/checkout@v3
    with:
      path: src

  - name: Run some action with output
    uses: ./src/action_with_output
    id: step1

  - name: Read output
    run: echo "${{ steps.step1.outputs.out }}"

I would expect the output of step Read output to be true, but instead, I do not get any output, as if the output variable never existed.
我期望步骤 Read output 的输出为 true,但实际上,我没有得到任何输出,就好像输出变量从未存在过。

You can see some test cases in this PR: https://github.com/eProsima/eProsima-CI/actions/runs/4945870294/jobs/8843185789?pr=26
您可以在此PR中查看一些测试案例:https://github.com/eProsima/eProsima-CI/actions/runs/4945870294/jobs/8843185789?pr=26

It works if I try the same but instead of calling the action action_with_output, I use this step:
如果我尝试相同的操作,但不是调用操作 action_with_output,而是使用以下步骤,它就可以正常工作:

  - name: Run some action with output
    run: echo "out=true" >> $GITHUB_OUTPUT
    id: step1
英文:

I am building my own Github-actions repository.
I am trying to use the output of an action in the following step, but I could not manage to do so.

This is a minimal example with what I want to do:

I have an action that do some stuff and stores an output value (boolean for instance). The minimum action.yml would be like this:

# action_with_output/action.yml
name: action_with_output

outputs:
  out:
    description: 'Some output'

runs:
  using: composite
  steps:
    - name: action with output step
      shell: bash
      run: echo "out=true" >> $GITHUB_OUTPUT

Then, in my workflow I want to use such output called out. Like this:

# .github/workflows/my_workflow.yml
...

workflow_name:
  runs-on: ubuntu-22.04
  steps:

  - name: Sync repository
    uses: actions/checkout@v3
    with:
      path: src

  - name: Run some action with output
    uses: ./src/action_with_output
    id: step1

  - name: Read output
    run: echo "${{ steps.step1.outputs.out }}"

I would expect the output of step Read output to be true, but instead I do not get any output, as if the output variable never existed.


You can see some test cases in this PR: https://github.com/eProsima/eProsima-CI/actions/runs/4945870294/jobs/8843185789?pr=26


It works if I try the same but instead of calling the action action_with_output, I use this step:

  - name: Run some action with output
    run: echo "out=true" >> $GITHUB_OUTPUT
    id: step1

答案1

得分: 1

I just figured out what I missed with this answer: https://stackoverflow.com/a/64471887/17049427

我刚刚弄清楚了我在这个答案中遗漏的部分:https://stackoverflow.com/a/64471887/17049427

I have to explicitly specify the value of each output variable as follows:

我必须明确指定每个输出变量的值如下所示:

# action_with_output/action.yml
name: action_with_output

outputs:
  out:
    description: 'Some output'
    value: ${{ steps.run.outputs.out }}

runs:
  using: composite
  steps:
    - name: action with output step
      id: run
      shell: bash
      run: echo "out=true" >> $GITHUB_OUTPUT
# action_with_output/action.yml
name: action_with_output

outputs:
  out:
    description: '一些输出'
    value: ${{ steps.run.outputs.out }}

runs:
  using: composite
  steps:
    - name: 带输出的操作步骤
      id: run
      shell: bash
      run: echo "out=true" >> $GITHUB_OUTPUT
英文:

Okey, I just figured out what I missed with this answer: https://stackoverflow.com/a/64471887/17049427

I have to explicitly specify the value of each output variable as follows:

# action_with_output/action.yml
name: action_with_output

outputs:
  out:
    description: 'Some output'
    value: ${{ steps.run.outputs.out }}

runs:
  using: composite
  steps:
    - name: action with output step
      id: run
      shell: bash
      run: echo "out=true" >> $GITHUB_OUTPUT

huangapple
  • 本文由 发表于 2023年5月11日 16:54:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76225806.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定