| title | Using conditions to control job execution | ||||||
|---|---|---|---|---|---|---|---|
| shortTitle | Control jobs with conditions | ||||||
| intro | Prevent a job from running unless your conditions are met. | ||||||
| versions |
|
||||||
| redirect_from |
|
||||||
| category |
|
||||||
| contentType | how-tos |
You can use the jobs.<job_id>.if conditional to prevent a job from running unless a condition is met. {% data reusables.actions.if-supported-contexts %}
Note that conditions executed by a shell (for example [[ $variable == "prefix"* ]]) can not be evaluated in jobs.<job_id>.if. Such conditions must be written inside jobs.<job_id>.steps[*].run.
This example uses if to control when the production-deploy job can run. It will only run if the repository is named octo-repo-prod and is within the octo-org organization. Otherwise, the job will be marked as skipped.
name: example-workflow
on: [push]
jobs:
production-deploy:
if: {% raw %}${{ github.repository == 'octo-org/octo-repo-prod' }}{% endraw %}
runs-on: ubuntu-latest
steps:
- uses: {% data reusables.actions.action-checkout %}
- uses: {% data reusables.actions.action-setup-node %}
with:
node-version: '14'
- run: npm install -g batsSkipped jobs display the message "This check was skipped."
Note
A job that is skipped will report its status as "Success". It will not prevent a pull request from merging, even if it is a required check.
{% ifversion fpt or ghec %}
To debug why a job was skipped or ran unexpectedly, you can view job condition expression logs. For more information, see AUTOTITLE.
{% endif %}