如何将动作的输出用作 Github 动作工作流的 if 条件中的表达式?

How to use output from an action as an expression in a if-condition for a Github Action workflow?

我正在构建一个工作流,其中一个动作为工作流中的一个步骤提供条件。我该如何使用这个值?

操作的值为空,因此评估为 false,并且从未部署过任何内容...

jobs:
  build:
    steps:
      - id: verify
        name: verify if artifact is eligable for deployment
        uses: my.org/my.action.group/my.action.path@my.branch
      - name: release candidate
        run: echo release candidate - "${{ steps.verify.is-release-candidate }}"
      - name: deploy
        run: ...
        if: steps.verify.is-release-candidate

调试发布候选:

Run echo release candidate - ""
release candidate - 

action.yml:

....
outputs:
  is-release-candidate:
    description: true if this new version can be auto deployed, false if not

试试用这个。您将在 find_output 变量中获得输出并在下一步中使用它。

jobs:
  build:
    steps:
      - id: verify
        name: verify if artifact is eligable for deployment
        uses: my.org/my.action.group/my.action.path@my.branch
        register : find_output
      - debug:
        var: find_output
      - name: deploy
        if: find_output.<use the key to validate>, yaml: A SEQUENCE WAS EXPECTED...

除了一个小细节,您几乎做对了 - 您在尝试访问 is-release-candidate 时跳过了 outputs 部分 - 正确版本:steps.<id>.outputs.<name>.

- name: release candidate
  run:  echo "release candidate - ${{ steps.verify.outputs.is-release-candidate }}"
- name: deploy
  run:  ...
  if:   steps.verify.outputs.is-release-candidate