【问题标题】:Why is my workflow triggering when previous fail?为什么我的工作流在之前失败时触发?
【发布时间】:2022-07-06 21:11:36
【问题描述】:

我有两个工作流程。工作流程 A 和 B。我只想在工作流程 A 完成时触发工作流程 B。但是当工作流A失败时,会触发工作流B吗?

我的工作流程 A:

name: Security

on:
  workflow_run:
    workflows: ["Bygg og test"]
    types:
      - completed
  schedule:
    - cron: '0 3 * * *'

我的工作流程 B:

name: Deploy dev og prod

on:
  workflow_run:
    workflows: ["Security"]
    types:
      - completed

env:
  IMAGE: ghcr.io/${{ github.repository }}:${{ github.sha }}

jobs:
  deploy-dev-gcp:
    name: Deploy til dev-gcp
    if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: nais/deploy/actions/deploy@v1
        env:
          APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
          CLUSTER: dev-gcp
          RESOURCE: .nais/naiserator.yaml
          VARS: .nais/dev-gcp.json

我错过了什么吗?

【问题讨论】:

  • 请注意,actions/checkout 操作在 v3 中可用

标签: github-actions


【解决方案1】:

docs 中所述,workflow_run 触发器会调用一个工作流,而不管其他工作流是否结束。

因此,如果您希望您的工作流仅在另一个成功运行时运行,请添加以下条件:

if: github.event.workflow_run.conclusion == 'success'

在你的情况下:

# ...
jobs:
  deploy-dev-gcp:
    name: Deploy til dev-gcp
    if: github.event.workflow_run.conclusion == 'success' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
# etc..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-14
    • 2014-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多