Reputation:
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:
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?
Upvotes: 0
Views: 118
Reputation: 8443
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..
Upvotes: 1