Skip to content

Commit fede3ca

Browse files
authored
Merge pull request #15970 from github/repo-sync
repo sync
2 parents 0b15d0d + f898304 commit fede3ca

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

content/actions/using-workflows/triggering-a-workflow.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ If you want more granular control than events, event activity types, or event fi
195195

196196
### Using conditionals
197197

198-
You can use conditionals to further control whether jobs or steps in your workflow will run. For example, if you want the workflow to run when a specific label is added to an issue, you can trigger on the `issues labeled` event activity type and use a conditional to check what label triggered the workflow. The following workflow will run when any label is added to an issue in the workflow's repository, but the `run_if_label_matches` job will only execute if the label is named `bug`.
198+
You can use conditionals to further control whether jobs or steps in your workflow will run.
199+
200+
#### Example using a value in the event payload
201+
202+
For example, if you want the workflow to run when a specific label is added to an issue, you can trigger on the `issues labeled` event activity type and use a conditional to check what label triggered the workflow. The following workflow will run when any label is added to an issue in the workflow's repository, but the `run_if_label_matches` job will only execute if the label is named `bug`.
199203

200204
```yaml
201205
on:
@@ -211,7 +215,34 @@ jobs:
211215
- run: echo 'The label was bug'
212216
```
213217
214-
For more information, see "[Expressions](/actions/learn-github-actions/expressions)."
218+
#### Example using event type
219+
220+
For example, if you want to run different jobs or steps depending on what event triggered the workflow, you can use a conditional to check whether a specific event type exists in the event context. The following workflow will run whenever an issue or pull request is closed. If the workflow ran because an issue was closed, the `github.event` context will contain a value for `issue` but not for `pull_request`. Therefore, the `if_issue` step will run but the `if_pr` step will not run. Conversely, if the workflow ran because a pull request was closed, the `if_pr` step will run but the `if_issue` step will not run.
221+
222+
```yaml
223+
on:
224+
issues:
225+
types:
226+
- closed
227+
pull_request:
228+
types:
229+
- closed
230+
231+
jobs:
232+
state_event_type:
233+
runs-on: ubuntu-latest
234+
steps:
235+
- name: if_issue
236+
if: github.event.issue
237+
run: |
238+
echo An issue was closed
239+
- name: if_pr
240+
if: github.event.pull_request
241+
run: |
242+
echo A pull request was closed
243+
```
244+
245+
For more information about what information is available in the event context, see "[Using event information](#using-event-information)." For more information about how to use conditionals, see "[Expressions](/actions/learn-github-actions/expressions)."
215246

216247
{% ifversion fpt or ghae or ghes > 3.1 or ghec %}
217248

0 commit comments

Comments
 (0)