Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
GitHub Docs

Contexts

Learn about contexts in GitHub Actions.

About contexts

Contexts are a way to access information about workflow runs, variables, runner environments, jobs, and steps. Each context is an object that contains properties, which can be strings or other objects.

Contexts, objects, and properties will vary significantly under different workflow run conditions. For example, thematrix context is only populated for jobs in amatrix.

You can access contexts using the expression syntax. For more information, seeEvaluate expressions in workflows and actions.

${{ <context> }}

Warning

When creating workflows and actions, you should always consider whether your code might execute untrusted input from possible attackers. Certain contexts should be treated as untrusted input, as an attacker could insert their own malicious content. For more information, seeSecure use reference.

Determining when to use contexts

GitHub Actions includes a collection of variables calledcontexts and a similar collection of variables calleddefault 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, seeStore information in variables.
  • Contexts: You can use most contexts at any point in your workflow, including whendefault 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 conditionalif 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 asrunner.os. For details of where you can use various contexts within a workflow, seeContexts reference.

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

YAML
name:CIon:pushjobs:prod-check:if:${{github.ref=='refs/heads/main'}}runs-on:ubuntu-lateststeps:-run:echo"Deploying to production server on branch $GITHUB_REF"

In this example, theif statement checks thegithub.ref context to determine the current branch name; if the name isrefs/heads/main, then the subsequent steps are executed. Theif check is processed by GitHub Actions, and the job is only sent to the runner if the result istrue. Once the job is sent to the runner, the step is executed and refers to the$GITHUB_REF variable from the runner.


[8]ページ先頭

©2009-2025 Movatter.jp