Skip to content

Commit 614ba96

Browse files
authored
Update contexts.md
1 parent a4cbcd2 commit 614ba96

1 file changed

Lines changed: 0 additions & 50 deletions

File tree

  • content/actions/concepts/workflows-and-actions
Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1 @@
1-
---
2-
title: Contexts
3-
intro: Learn about contexts in {% data variables.product.prodname_actions %}.
4-
versions:
5-
fpt: '*'
6-
ghes: '*'
7-
ghec: '*'
8-
contentType: concepts
9-
category:
10-
- Write workflows
11-
---
121

13-
## About contexts
14-
15-
{% data reusables.actions.actions-contexts-about-description %} Each context is an object that contains properties, which can be strings or other objects.
16-
17-
{% data reusables.actions.context-contents %} For example, the `matrix` context is only populated for jobs in a [matrix](/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idstrategymatrix).
18-
19-
You can access contexts using the expression syntax. For more information, see [AUTOTITLE](/actions/reference/workflows-and-actions/expressions).
20-
21-
{% raw %}
22-
`${{ <context> }}`
23-
{% endraw %}
24-
25-
{% data reusables.actions.context-injection-warning %}
26-
27-
## Determining when to use contexts
28-
29-
{% 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:
30-
31-
* **Default environment variables:** These environment variables exist only on the runner that is executing your job. For more information, see [AUTOTITLE](/actions/reference/workflows-and-actions/variables#default-environment-variables).
32-
* **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/workflows-and-actions/contexts#context-availability).
33-
34-
The following example demonstrates how these different types of variables can be used together in a job:
35-
36-
{% raw %}
37-
38-
```yaml copy
39-
name: CI
40-
on: push
41-
jobs:
42-
prod-check:
43-
if: ${{ github.ref == 'refs/heads/main' }}
44-
runs-on: ubuntu-latest
45-
steps:
46-
- run: echo "Deploying to production server on branch $GITHUB_REF"
47-
```
48-
49-
{% endraw %}
50-
51-
In this example, the `if` statement checks the [`github.ref`](/actions/reference/workflows-and-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/how-tos/write-workflows/choose-what-workflows-do/use-variables) variable from the runner.

0 commit comments

Comments
 (0)