In GitHub Actions, I have defined pipeline in YAML.
I have one conditional job and another one after, that I would like to execute after the conditional job. But if the job does not execute, then execute it immediately.
If I use:
name: Test conditionals
on:
workflow_dispatch:
env:
DEPLOY_NONPROD_ENV: 'false'
jobs:
conditionalJob:
if: ${{ env.DEPLOY_NONPROD_ENV == 'true' }}
runs-on: 'ubuntu-latest'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Echo message
run: 'echo "Condition evaluated to true"'
dependantJob:
needs: [conditionalJob]
runs-on: 'ubuntu-latest'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Echo message
run: 'echo "Running dependantJob"'
if conditionalJob
is skipped, then the dependantJob
is also skipped.
How to make it work so dependantJob
executes immediately if conditionalJob
is skipped and wait for it if it runs?
Actually the answers in comment's question not %100 good, in this case you need to check the result
of the first job, if it pass or skipped, but need also to add !cancelled()
, this should work:
if: (needs.conditionalJob.result == 'skipped' || needs.conditionalJob.result == 'success') && !cancelled()
You can replace !cancelled()
with always()
but then the workflow will keep running even you cancel it!