Skip to content

Commit c2ff56c

Browse files
authored
EDI-ify "Using conditions to control job execution" (#56627)
1 parent 3c0657b commit c2ff56c

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Using conditions to control job execution
3-
shortTitle: Use conditions to control job execution
3+
shortTitle: Control jobs with conditions
44
intro: Prevent a job from running unless your conditions are met.
55
versions:
66
fpt: '*'
@@ -11,15 +11,28 @@ redirect_from:
1111
- /actions/writing-workflows/choosing-when-your-workflow-runs/using-conditions-to-control-job-execution
1212
---
1313

14-
{% data reusables.actions.enterprise-github-hosted-runners %}
14+
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 %}
1515

16-
## Overview
16+
### Example: Only run job for a specific repository
1717

18-
{% data reusables.actions.workflows.skipped-job-status-checks-passing %}
18+
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_.
1919

20-
{% data reusables.actions.jobs.section-using-conditions-to-control-job-execution %}
20+
```yaml copy
21+
name: example-workflow
22+
on: [push]
23+
jobs:
24+
production-deploy:
25+
if: github.repository == 'octo-org/octo-repo-prod'
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: {% data reusables.actions.action-checkout %}
29+
- uses: {% data reusables.actions.action-setup-node %}
30+
with:
31+
node-version: '14'
32+
- run: npm install -g bats
33+
```
2134
22-
On a skipped job, you should see "This check was skipped."
35+
Skipped jobs display the message "This check was skipped."
2336
2437
> [!NOTE]
25-
> In some parts of the workflow you cannot use environment variables. Instead you can use contexts to access the value of an environment variable. For more information, see [AUTOTITLE](/actions/learn-github-actions/variables#using-the-env-context-to-access-environment-variable-values).
38+
> 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.

0 commit comments

Comments
 (0)