Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/images/social-cards/copilot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Many people access {% data variables.product.github %} at a domain other than {%

To ensure that your action is compatible with other platforms, do not use any hard-coded references to API URLs such as `https://api.github.com`. Instead, you can:

* Use environment variables (see [AUTOTITLE](/actions/learn-github-actions/variables#default-environment-variables)):
* Use environment variables (see [AUTOTITLE](/actions/reference/variables-reference#default-environment-variables)):

* For the REST API, use the `GITHUB_API_URL` environment variable.
* For GraphQL, use the `GITHUB_GRAPHQL_URL` environment variable.
Expand Down
53 changes: 53 additions & 0 deletions content/actions/concepts/workflows-and-actions/contexts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Contexts
shortTitle: Contexts
intro: 'Learn about contexts in {% data variables.product.prodname_actions %}.'
versions:
fpt: '*'
ghes: '*'
ghec: '*'
type: overview
topics:
- Actions
- Workflows
---

## About contexts

{% data reusables.actions.actions-contexts-about-description %} Each context is an object that contains properties, which can be strings or other objects.

{% 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).

You can access contexts using the expression syntax. For more information, see [AUTOTITLE](/actions/learn-github-actions/expressions).

{% raw %}
`${{ <context> }}`
{% endraw %}

{% data reusables.actions.context-injection-warning %}

## Determining when to use contexts

{% 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:

* **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).
* **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).

The following example demonstrates how these different types of variables can be used together in a job:

{% raw %}

```yaml copy
name: CI
on: push
jobs:
prod-check:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
steps:
- run: echo "Deploying to production server on branch $GITHUB_REF"
```

{% endraw %}

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.
2 changes: 2 additions & 0 deletions content/actions/concepts/workflows-and-actions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ versions:
ghec: '*'
children:
- /about-workflows
- /variables
- /avoiding-duplication
- /about-custom-actions
- /contexts
- /about-monitoring-workflows
- /notifications-for-workflow-runs
- /about-troubleshooting-workflows
Expand Down
28 changes: 28 additions & 0 deletions content/actions/concepts/workflows-and-actions/variables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: Variables
intro: 'Learn about variables in {% data variables.product.prodname_actions %} workflows.'
versions:
fpt: '*'
ghes: '*'
ghec: '*'
type: overview
topics:
- Action development
- Fundamentals
---

## About

Variables provide a way to store and reuse non-sensitive configuration information. You can store any configuration data such as compiler flags, usernames, or server names as variables. Variables are interpolated on the runner machine that runs your workflow. Commands that run in actions or workflow steps can create, read, and modify variables.

You can set your own custom variables or use the default environment variables that {% data variables.product.prodname_dotcom %} sets automatically.

You can set a custom variable in two ways.

* To define an environment variable for use in a single workflow, you can use the `env` key in the workflow file. For more information, see [Defining environment variables for a single workflow](/actions/how-tos/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#defining-environment-variables-for-a-single-workflow).
* To define a configuration variable across multiple workflows, you can define it at the organization, repository, or environment level. For more information, see [Defining configuration variables for multiple workflows](/actions/how-tos/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#defining-configuration-variables-for-multiple-workflows).

> [!WARNING]
> By default, variables render unmasked in your build outputs. If you need greater security for sensitive information, such as passwords, use secrets instead. For more information, see [AUTOTITLE](/actions/security-for-github-actions/security-guides/about-secrets).

For reference documentation, see [AUTOTITLE](/actions/reference/variables-reference).
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The following scripting languages are supported:

Your custom scripts can use the following features:

* **Variables:** Scripts have access to the default variables. The full webhook event payload can be found in `GITHUB_EVENT_PATH`. For more information, see [AUTOTITLE](/actions/learn-github-actions/variables#default-environment-variables).
* **Variables:** Scripts have access to the default variables. The full webhook event payload can be found in `GITHUB_EVENT_PATH`. For more information, see [AUTOTITLE](/actions/reference/variables-reference#default-environment-variables).
* **Workflow commands:** Scripts can use workflow commands. For more information, see [AUTOTITLE](/actions/using-workflows/workflow-commands-for-github-actions). Scripts can also use environment files. For more information, see [Environment files](/actions/using-workflows/workflow-commands-for-github-actions#environment-files).

Your script files must use a file extension for the relevant language, such as `.sh` or `.ps1`, in order to run successfully.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ For more information about the tools and packages available on {% data variables

CircleCI and {% data variables.product.prodname_actions %} support setting variables in the configuration file and creating secrets using the CircleCI or {% data variables.product.github %} UI.

For more information, see [AUTOTITLE](/actions/learn-github-actions/variables#default-environment-variables) and [AUTOTITLE](/actions/security-guides/using-secrets-in-github-actions).
For more information, see [AUTOTITLE](/actions/reference/variables-reference#default-environment-variables) and [AUTOTITLE](/actions/security-guides/using-secrets-in-github-actions).

## Caching

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Travis CI lets you set variables and share them between stages. Similarly, {% da

### Default variables

Travis CI and {% data variables.product.prodname_actions %} both include default environment variables that you can use in your YAML files. For {% data variables.product.prodname_actions %}, you can see these listed in [AUTOTITLE](/actions/learn-github-actions/variables#default-environment-variables).
Travis CI and {% data variables.product.prodname_actions %} both include default environment variables that you can use in your YAML files. For {% data variables.product.prodname_actions %}, you can see these listed in [AUTOTITLE](/actions/reference/variables-reference#default-environment-variables).

### Parallel job processing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ To ensure proper communications for {% data variables.product.github %}-hosted r
| `workspace` | `GITHUB_WORKSPACE` | Actions and shell commands execute in this directory. An action can modify the contents of this directory, which subsequent actions can access. |
| `workflow/event.json` | `GITHUB_EVENT_PATH` | The `POST` payload of the webhook event that triggered the workflow. {% data variables.product.prodname_dotcom %} rewrites this each time an action executes to isolate file content between actions.

For a list of the environment variables {% data variables.product.prodname_dotcom %} creates for each workflow, see [AUTOTITLE](/actions/learn-github-actions/variables#default-environment-variables).
For a list of the environment variables {% data variables.product.prodname_dotcom %} creates for each workflow, see [AUTOTITLE](/actions/reference/variables-reference#default-environment-variables).

### Docker container filesystem

Expand Down
Loading
Loading