Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my workflow triggering when previous fail?

I have two workflow. Workflow A and B. I want to trigger workflow B only when workflow A is completed. But when workflow A fail, workflow B is being triggered?

My workflow A:

name: Security

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

My workflow B:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Am I missing something?

>Solution :

As described in the docs, the workflow_run trigger invokes a workflow regardless of the conclusion of the other workflow.

Therefore, if you want your workflow to only run if the other one ran successfully, add this condition:

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

In your case:

# ...
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..
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading