You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
intro: 'Learn about contexts in {% data variables.product.prodname_actions %}.'
5
+
versions:
6
+
fpt: '*'
7
+
ghes: '*'
8
+
ghec: '*'
9
+
type: overview
10
+
topics:
11
+
- Actions
12
+
- Workflows
13
+
---
14
+
15
+
## About contexts
16
+
17
+
{% data reusables.actions.actions-contexts-about-description %} Each context is an object that contains properties, which can be strings or other objects.
18
+
19
+
{% data reusables.actions.context-contents %} For example, the `matrix` context is only populated for jobs in a [matrix](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix).
20
+
21
+
You can access contexts using the expression syntax. For more information, see [AUTOTITLE](/actions/learn-github-actions/expressions).
22
+
23
+
{% raw %}
24
+
`${{ <context> }}`
25
+
{% endraw %}
26
+
27
+
{% data reusables.actions.context-injection-warning %}
28
+
29
+
## Determining when to use contexts
30
+
31
+
{% data variables.product.prodname_actions %} includes a collection of variables called _contexts_ and a similar collection of variables called _default variables_. These variables are intended for use at different points in the workflow:
32
+
33
+
***Default environment variables:** These environment variables exist only on the runner that is executing your job. For more information, see [AUTOTITLE](/actions/learn-github-actions/variables#default-environment-variables).
34
+
***Contexts:** You can use most contexts at any point in your workflow, including when _default variables_ would be unavailable. For example, you can use contexts with expressions to perform initial processing before the job is routed to a runner for execution; this allows you to use a context with the conditional `if` keyword to determine whether a step should run. Once the job is running, you can also retrieve context variables from the runner that is executing the job, such as `runner.os`. For details of where you can use various contexts within a workflow, see [AUTOTITLE](/actions/reference/accessing-contextual-information-about-workflow-runs#context-availability).
35
+
36
+
The following example demonstrates how these different types of variables can be used together in a job:
37
+
38
+
{% raw %}
39
+
40
+
```yaml copy
41
+
name: CI
42
+
on: push
43
+
jobs:
44
+
prod-check:
45
+
if: ${{ github.ref == 'refs/heads/main' }}
46
+
runs-on: ubuntu-latest
47
+
steps:
48
+
- run: echo "Deploying to production server on branch $GITHUB_REF"
49
+
```
50
+
51
+
{% endraw %}
52
+
53
+
In this example, the `if` statement checks the [`github.ref`](/actions/learn-github-actions/contexts#github-context) context to determine the current branch name; if the name is `refs/heads/main`, then the subsequent steps are executed. The `if` check is processed by {% data variables.product.prodname_actions %}, and the job is only sent to the runner if the result is `true`. Once the job is sent to the runner, the step is executed and refers to the [`$GITHUB_REF`](/actions/learn-github-actions/variables#default-environment-variables) variable from the runner.
Copy file name to clipboardExpand all lines: content/actions/reference/contexts-reference.md
+10-19Lines changed: 10 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: Accessing contextual information about workflow runs
3
-
shortTitle: Contexts
4
-
intro: You can access context information in workflowsand actions.
2
+
title: Contexts reference
3
+
shortTitle: Contexts reference
4
+
intro: 'Find information about contexts available in {% data variables.product.prodname_actions %} workflows, including available properties, access methods, and usage examples.'
{% data reusables.actions.enterprise-github-hosted-runners %}
21
-
22
-
## About contexts
23
-
24
-
{% data reusables.actions.actions-contexts-about-description %} Each context is an object that contains properties, which can be strings or other objects.
25
-
26
-
{% data reusables.actions.context-contents %} For example, the `matrix` context is only populated for jobs in a [matrix](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix).
27
-
28
-
You can access contexts using the expression syntax. For more information, see [AUTOTITLE](/actions/learn-github-actions/expressions).
29
-
30
-
{% raw %}
31
-
`${{ <context> }}`
32
-
{% endraw %}
33
-
34
-
{% data reusables.actions.context-injection-warning %}
21
+
## Available contexts
35
22
36
23
| Context name | Type | Description |
37
24
|---------------|------|-------------|
@@ -174,7 +161,7 @@ jobs:
174
161
175
162
## `github` context
176
163
177
-
The `github` context contains information about the workflow run and the event that triggered the run. You can also read most of the `github` context data in environment variables. For more information about environment variables, see [AUTOTITLE](/actions/learn-github-actions/variables).
164
+
The `github` context contains information about the workflow run and the event that triggered the run. You can read most of the `github` context data in environment variables. For more information about environment variables, see [AUTOTITLE](/actions/learn-github-actions/variables).
178
165
179
166
{% data reusables.actions.github-context-warning %}
180
167
{% data reusables.actions.context-injection-warning %}
0 commit comments