I’m working on a GitHub Actions workflow with several jobs for CI/CD. Some jobs are not being triggered as expected, despite previous jobs completing successfully:
- The
deploy-env
job should start only after all the build jobs (build-x
,build-y
) have completed (successfully or unsuccessfully). This works fine. - The
comment
job should be triggered after thedeploy-env
job has finished.
<code>jobs:
build-x:
if: github.event.pull_request.state != 'closed' && contains(github.event.pull_request.labels.*.name, 'deploy')
runs-on: ubuntu-latest
steps:
# ... steps for building X
build-y:
if: github.event.pull_request.state != 'closed' && contains(github.event.pull_request.labels.*.name, 'deploy')
runs-on: ubuntu-latest
steps:
# ... steps for building Y
deploy-env:
if: always()
needs: [build-x, build-y]
runs-on: ubuntu-22.04
steps:
# ... steps for deploying
comment:
if: always() && needs.deploy-env.result != 'skipped'
needs: [deploy-env]
runs-on: ubuntu-22.04
steps:
# ... steps for commenting
</code>
<code>jobs:
build-x:
if: github.event.pull_request.state != 'closed' && contains(github.event.pull_request.labels.*.name, 'deploy')
runs-on: ubuntu-latest
steps:
# ... steps for building X
build-y:
if: github.event.pull_request.state != 'closed' && contains(github.event.pull_request.labels.*.name, 'deploy')
runs-on: ubuntu-latest
steps:
# ... steps for building Y
deploy-env:
if: always()
needs: [build-x, build-y]
runs-on: ubuntu-22.04
steps:
# ... steps for deploying
comment:
if: always() && needs.deploy-env.result != 'skipped'
needs: [deploy-env]
runs-on: ubuntu-22.04
steps:
# ... steps for commenting
</code>
jobs:
build-x:
if: github.event.pull_request.state != 'closed' && contains(github.event.pull_request.labels.*.name, 'deploy')
runs-on: ubuntu-latest
steps:
# ... steps for building X
build-y:
if: github.event.pull_request.state != 'closed' && contains(github.event.pull_request.labels.*.name, 'deploy')
runs-on: ubuntu-latest
steps:
# ... steps for building Y
deploy-env:
if: always()
needs: [build-x, build-y]
runs-on: ubuntu-22.04
steps:
# ... steps for deploying
comment:
if: always() && needs.deploy-env.result != 'skipped'
needs: [deploy-env]
runs-on: ubuntu-22.04
steps:
# ... steps for commenting
Although the deploy-env
completes succesfully, the comment
job never runs and it gets skipped. Why is this the case?