【问题标题】:How do i skip a Github action?我如何跳过 Github 操作?
【发布时间】:2022-11-25 19:54:33
【问题描述】:

我想在整个复合操作而不是单个步骤上应用 if 条件。例如,跳过 dependabot 的操作会很棒。我可以在工作流级别添加 if 语句,但我想知道是否可以在操作级别添加。

https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsstepsshell

示例示例:

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-number }}
runs:
  using: "composite"
  steps:
    - run: echo Hello ${{ inputs.who-to-greet }}.
      shell: bash
    - id: random-number-generator
      run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
      shell: bash
    - run: echo "${{ github.action_path }}" >> $GITHUB_PATH
      shell: bash
    - run: goodbye.sh
      shell: bash

复合动作可以在根级别有 if 语句来跳过它吗?

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-number }}
runs:
  using: "composite"
  if: github.actor != 'dependabot[bot]'
  steps:
    - run: echo Hello ${{ inputs.who-to-greet }}.
      shell: bash
    - id: random-number-generator
      run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
      shell: bash
    - run: echo "${{ github.action_path }}" >> $GITHUB_PATH
      shell: bash
    - run: goodbye.sh
      shell: bash

【问题讨论】:

  • 你是说if condition of a job
  • @tmt 为工作添加一个简单的 if 很简单,但我还没有看到复合操作的功能

标签: github-actions


【解决方案1】:

你可以像这样跳过整个工作:

  compliance-check:
    if: github.actor != 'dependabot[bot]'
    runs-on: ubuntu-latest
    steps:

【讨论】:

  • 我知道这在工作流程级别是可能的,但我希望在复合操作中做到这一点。通过编辑查看详细信息
猜你喜欢
  • 2021-10-29
  • 2020-06-08
  • 2021-05-13
  • 2021-09-14
  • 1970-01-01
  • 1970-01-01
  • 2022-11-08
  • 2020-05-02
  • 2021-01-19
相关资源
最近更新 更多