Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
GitHub Docs

Contexts reference

Find information about contexts available in GitHub Actions workflows, including available properties, access methods, and usage examples.

Available contexts

Context nameTypeDescription
githubobjectInformation about the workflow run. For more information, seegithub context.
envobjectContains variables set in a workflow, job, or step. For more information, seeenv context.
varsobjectContains variables set at the repository, organization, or environment levels. For more information, seevars context.
jobobjectInformation about the currently running job. For more information, seejob context.
jobsobjectFor reusable workflows only, contains outputs of jobs from the reusable workflow. For more information, seejobs context.
stepsobjectInformation about the steps that have been run in the current job. For more information, seesteps context.
runnerobjectInformation about the runner that is running the current job. For more information, seerunner context.
secretsobjectContains the names and values of secrets that are available to a workflow run. For more information, seesecrets context.
strategyobjectInformation about the matrix execution strategy for the current job. For more information, seestrategy context.
matrixobjectContains the matrix properties defined in the workflow that apply to the current job. For more information, seematrix context.
needsobjectContains the outputs of all jobs that are defined as a dependency of the current job. For more information, seeneeds context.
inputsobjectContains the inputs of a reusable or manually triggered workflow. For more information, seeinputs context.

As part of an expression, you can access context information using one of two syntaxes.

  • Index syntax:github['sha']
  • Property dereference syntax:github.sha

In order to use property dereference syntax, the property name must start with a letter or_ and contain only alphanumeric characters,-, or_.

If you attempt to dereference a nonexistent property, it will evaluate to an empty string.

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, seeVariables reference.
  • 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, seeContext availability.

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.

Context availability

Different contexts are available throughout a workflow run. For example, thesecrets context may only be used at certain places within a job.

In addition, some functions may only be used in certain places. For example, thehashFiles function is not available everywhere.

The following table lists the restrictions on where each context and special function can be used within a workflow. The listed contexts are only available for the given workflow key, and may not be used anywhere else. Unless listed below, a function can be used anywhere.

Workflow keyContextSpecial functions
run-namegithub, inputs, varsNone
concurrencygithub, inputs, varsNone
envgithub, secrets, inputs, varsNone
jobs.<job_id>.concurrencygithub, needs, strategy, matrix, inputs, varsNone
jobs.<job_id>.containergithub, needs, strategy, matrix, vars, inputsNone
jobs.<job_id>.container.credentialsgithub, needs, strategy, matrix, env, vars, secrets, inputsNone
jobs.<job_id>.container.env.<env_id>github, needs, strategy, matrix, job, runner, env, vars, secrets, inputsNone
jobs.<job_id>.container.imagegithub, needs, strategy, matrix, vars, inputsNone
jobs.<job_id>.continue-on-errorgithub, needs, strategy, vars, matrix, inputsNone
jobs.<job_id>.defaults.rungithub, needs, strategy, matrix, env, vars, inputsNone
jobs.<job_id>.envgithub, needs, strategy, matrix, vars, secrets, inputsNone
jobs.<job_id>.environmentgithub, needs, strategy, matrix, vars, inputsNone
jobs.<job_id>.environment.urlgithub, needs, strategy, matrix, job, runner, env, vars, steps, inputsNone
jobs.<job_id>.ifgithub, needs, vars, inputsalways, cancelled, success, failure
jobs.<job_id>.namegithub, needs, strategy, matrix, vars, inputsNone
jobs.<job_id>.outputs.<output_id>github, needs, strategy, matrix, job, runner, env, vars, secrets, steps, inputsNone
jobs.<job_id>.runs-ongithub, needs, strategy, matrix, vars, inputsNone
jobs.<job_id>.secrets.<secrets_id>github, needs, strategy, matrix, secrets, inputs, varsNone
jobs.<job_id>.servicesgithub, needs, strategy, matrix, vars, inputsNone
jobs.<job_id>.services.<service_id>.credentialsgithub, needs, strategy, matrix, env, vars, secrets, inputsNone
jobs.<job_id>.services.<service_id>.env.<env_id>github, needs, strategy, matrix, job, runner, env, vars, secrets, inputsNone
jobs.<job_id>.steps.continue-on-errorgithub, needs, strategy, matrix, job, runner, env, vars, secrets, steps, inputshashFiles
jobs.<job_id>.steps.envgithub, needs, strategy, matrix, job, runner, env, vars, secrets, steps, inputshashFiles
jobs.<job_id>.steps.ifgithub, needs, strategy, matrix, job, runner, env, vars, steps, inputsalways, cancelled, success, failure, hashFiles
jobs.<job_id>.steps.namegithub, needs, strategy, matrix, job, runner, env, vars, secrets, steps, inputshashFiles
jobs.<job_id>.steps.rungithub, needs, strategy, matrix, job, runner, env, vars, secrets, steps, inputshashFiles
jobs.<job_id>.steps.timeout-minutesgithub, needs, strategy, matrix, job, runner, env, vars, secrets, steps, inputshashFiles
jobs.<job_id>.steps.withgithub, needs, strategy, matrix, job, runner, env, vars, secrets, steps, inputshashFiles
jobs.<job_id>.steps.working-directorygithub, needs, strategy, matrix, job, runner, env, vars, secrets, steps, inputshashFiles
jobs.<job_id>.strategygithub, needs, vars, inputsNone
jobs.<job_id>.timeout-minutesgithub, needs, strategy, matrix, vars, inputsNone
jobs.<job_id>.with.<with_id>github, needs, strategy, matrix, inputs, varsNone
on.workflow_call.inputs.<inputs_id>.defaultgithub, inputs, varsNone
on.workflow_call.outputs.<output_id>.valuegithub, jobs, vars, inputsNone

Example: printing context information to the log

You can print the contents of contexts to the log for debugging. ThetoJSON function is required to pretty-print JSON objects to the log.

Warning

When using the wholegithub context, be mindful that it includes sensitive information such asgithub.token. GitHub masks secrets when they are printed to the console, but you should be cautious when exporting or printing the context.

YAML
name:Contexttestingon:pushjobs:dump_contexts_to_log:runs-on:ubuntu-lateststeps:-name:DumpGitHubcontextenv:GITHUB_CONTEXT:${{toJson(github)}}run:echo"$GITHUB_CONTEXT"-name:Dumpjobcontextenv:JOB_CONTEXT:${{toJson(job)}}run:echo"$JOB_CONTEXT"-name:Dumpstepscontextenv:STEPS_CONTEXT:${{toJson(steps)}}run:echo"$STEPS_CONTEXT"-name:Dumprunnercontextenv:RUNNER_CONTEXT:${{toJson(runner)}}run:echo"$RUNNER_CONTEXT"-name:Dumpstrategycontextenv:STRATEGY_CONTEXT:${{toJson(strategy)}}run:echo"$STRATEGY_CONTEXT"-name:Dumpmatrixcontextenv:MATRIX_CONTEXT:${{toJson(matrix)}}run:echo"$MATRIX_CONTEXT"

github context

Thegithub context contains information about the workflow run and the event that triggered the run. You can read most of thegithub context data in environment variables. For more information about environment variables, seeStore information in variables.

Warning

When using the wholegithub context, be mindful that it includes sensitive information such asgithub.token. GitHub masks secrets when they are printed to the console, but you should be cautious when exporting or printing the context.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.

Property nameTypeDescription
githubobjectThe top-level context available during any job or step in a workflow. This object contains all the properties listed below.
github.actionstringThe name of the action currently running, or theid of a step. GitHub removes special characters, and uses the name__run when the current step runs a script without anid. If you use the same action more than once in the same job, the name will include a suffix with the sequence number with underscore before it. For example, the first script you run will have the name__run, and the second script will be named__run_2. Similarly, the second invocation ofactions/checkout will beactionscheckout2.
github.action_pathstringThe path where an action is located. This property is only supported in composite actions. You can use this path to access files located in the same repository as the action, for example by changing directories to the path:cd ${{ github.action_path }} .
github.action_refstringFor a step executing an action, this is the ref of the action being executed. For example,v2.

Do not use in therun keyword. To make this context work with composite actions, reference it within theenv context of the composite action.
github.action_repositorystringFor a step executing an action, this is the owner and repository name of the action. For example,actions/checkout.

Do not use in therun keyword. To make this context work with composite actions, reference it within theenv context of the composite action.
github.action_statusstringFor a composite action, the current result of the composite action.
github.actorstringThe username of the user that triggered the initial workflow run. If the workflow run is a re-run, this value may differ fromgithub.triggering_actor. Any workflow re-runs will use the privileges ofgithub.actor, even if the actor initiating the re-run (github.triggering_actor) has different privileges.
github.actor_idstringThe account ID of the person or app that triggered the initial workflow run. For example,1234567. Note that this is different from the actor username.
github.api_urlstringThe URL of the GitHub REST API.
github.base_refstringThebase_ref or target branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is eitherpull_request orpull_request_target.
github.envstringPath on the runner to the file that sets environment variables from workflow commands. This file is unique to the current step and is a different file for each step in a job. For more information, seeWorkflow commands for GitHub Actions.
github.eventobjectThe full event webhook payload. You can access individual properties of the event using this context. This object is identical to the webhook payload of the event that triggered the workflow run, and is different for each event. The webhooks for each GitHub Actions event is linked inEvents that trigger workflows. For example, for a workflow run triggered by thepush event, this object contains the contents of thepush webhook payload.
github.event_namestringThe name of the event that triggered the workflow run.
github.event_pathstringThe path to the file on the runner that contains the full event webhook payload.
github.graphql_urlstringThe URL of the GitHub GraphQL API.
github.head_refstringThehead_ref or source branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is eitherpull_request orpull_request_target.
github.jobstringThejob_id of the current job.
Note: This context property is set by the Actions runner, and is only available within the executionsteps of a job. Otherwise, the value of this property will benull.
github.pathstringPath on the runner to the file that sets systemPATH variables from workflow commands. This file is unique to the current step and is a different file for each step in a job. For more information, seeWorkflow commands for GitHub Actions.
github.refstringThe fully-formed ref of the branch or tag that triggered the workflow run. For workflows triggered bypush, this is the branch or tag ref that was pushed. For workflows triggered bypull_request, this is the pull request merge branch. For workflows triggered byrelease, this is the release tag created. For other triggers, this is the branch or tag ref that triggered the workflow run. This is only set if a branch or tag is available for the event type. The ref given is fully-formed, meaning that for branches the format isrefs/heads/<branch_name>. For pull requests events exceptpull_request_target, it isrefs/pull/<pr_number>/merge.pull_request_target events have theref from the base branch. For tags it isrefs/tags/<tag_name>. For example,refs/heads/feature-branch-1.
github.ref_namestringThe short ref name of the branch or tag that triggered the workflow run. This value matches the branch or tag name shown on GitHub. For example,feature-branch-1.

For pull requests, the format is<pr_number>/merge.
github.ref_protectedbooleantrue if branch protections orrulesets are configured for the ref that triggered the workflow run.
github.ref_typestringThe type of ref that triggered the workflow run. Valid values arebranch ortag.
github.repositorystringThe owner and repository name. For example,octocat/Hello-World.
github.repository_idstringThe ID of the repository. For example,123456789. Note that this is different from the repository name.
github.repository_ownerstringThe repository owner's username. For example,octocat.
github.repository_owner_idstringThe repository owner's account ID. For example,1234567. Note that this is different from the owner's name.
github.repositoryUrlstringThe Git URL to the repository. For example,git://github.com/octocat/hello-world.git.
github.retention_daysstringThe number of days that workflow run logs and artifacts are kept.
github.run_idstringA unique number for each workflow run within a repository. This number does not change if you re-run the workflow run.
github.run_numberstringA unique number for each run of a particular workflow in a repository. This number begins at 1 for the workflow's first run, and increments with each new run. This number does not change if you re-run the workflow run.
github.run_attemptstringA unique number for each attempt of a particular workflow run in a repository. This number begins at 1 for the workflow run's first attempt, and increments with each re-run.
github.secret_sourcestringThe source of a secret used in a workflow. Possible values areNone,Actions,Codespaces, orDependabot.
github.server_urlstringThe URL of the GitHub server. For example:https://github.com.
github.shastringThe commit SHA that triggered the workflow. The value of this commit SHA depends on the event that triggered the workflow. For more information, seeEvents that trigger workflows. For example,ffac537e6cbbf934b08745a378932722df287a53.
github.tokenstringA token to authenticate on behalf of the GitHub App installed on your repository. This is functionally equivalent to theGITHUB_TOKEN secret. For more information, seeUse GITHUB_TOKEN in workflows.
Note: This context property is set by the Actions runner, and is only available within the executionsteps of a job. Otherwise, the value of this property will benull.
github.triggering_actorstringThe username of the user that initiated the workflow run. If the workflow run is a re-run, this value may differ fromgithub.actor. Any workflow re-runs will use the privileges ofgithub.actor, even if the actor initiating the re-run (github.triggering_actor) has different privileges.
github.workflowstringThe name of the workflow. If the workflow file doesn't specify aname, the value of this property is the full path of the workflow file in the repository.
github.workflow_refstringThe ref path to the workflow. For example,octocat/hello-world/.github/workflows/my-workflow.yml@refs/heads/my_branch.
github.workflow_shastringThe commit SHA for the workflow file.
github.workspacestringThe default working directory on the runner for steps, and the default location of your repository when using thecheckout action.

Example contents of thegithub context

The following example context is from a workflow run triggered by thepush event. Theevent object in this example has been truncated because it is identical to the contents of thepush webhook payload.

Note

This context is an example only. The contents of a context depends on the workflow that you are running. Contexts, objects, and properties will vary significantly under different workflow run conditions.

{"token":"***","job":"dump_contexts_to_log","ref":"refs/heads/my_branch","sha":"c27d339ee6075c1f744c5d4b200f7901aad2c369","repository":"octocat/hello-world","repository_owner":"octocat","repositoryUrl":"git://github.com/octocat/hello-world.git","run_id":"1536140711","run_number":"314","retention_days":"90","run_attempt":"1","actor":"octocat","workflow":"Context testing","head_ref":"","base_ref":"","event_name":"push","event":{    ...},"server_url":"https://github.com","api_url":"https://api.github.com","graphql_url":"https://api.github.com/graphql","ref_name":"my_branch","ref_protected":false,"ref_type":"branch","secret_source":"Actions","workspace":"/home/runner/work/hello-world/hello-world","action":"github_step","event_path":"/home/runner/work/_temp/_github_workflow/event.json","action_repository":"","action_ref":"","path":"/home/runner/work/_temp/_runner_file_commands/add_path_b037e7b5-1c88-48e2-bf78-eaaab5e02602","env":"/home/runner/work/_temp/_runner_file_commands/set_env_b037e7b5-1c88-48e2-bf78-eaaab5e02602"}

Example usage of thegithub context

This example workflow uses thegithub.event_name context to run a job only if the workflow run was triggered by thepull_request event.

YAML
name:RunCIon: [push,pull_request]jobs:normal_ci:runs-on:ubuntu-lateststeps:-name:RunnormalCIrun:echo"Running normal CI"pull_request_ci:runs-on:ubuntu-latestif:${{github.event_name=='pull_request'}}steps:-name:RunPRCIrun:echo"Running PR only CI"

env context

Theenv context contains variables that have been set in a workflow, job, or step. It does not contain variables inherited by the runner process. For more information about setting variables in your workflow, seeWorkflow syntax for GitHub Actions.

You can retrieve the values of variables stored inenv context and use these values in your workflow file. You can use theenv context in any key in a workflow step except for theid anduses keys. For more information on the step syntax, seeWorkflow syntax for GitHub Actions.

If you want to use the value of a variable inside a runner, use the runner operating system's normal method for reading environment variables.

Property nameTypeDescription
envobjectThis context changes for each step in a job. You can access this context from any step in a job. This object contains the properties listed below.
env.<env_name>stringThe value of a specific environment variable.

Example contents of theenv context

The contents of theenv context is a mapping of variable names to their values. The context's contents can change depending on where it is used in the workflow run. In this example, theenv context contains two variables.

{"first_name":"Mona","super_duper_var":"totally_awesome"}

Example usage of theenv context

This example workflow shows variables being set in theenv context at the workflow, job, and step levels. The${{ env.VARIABLE-NAME }} syntax is then used to retrieve variable values within individual steps in the workflow.

When more than one environment variable is defined with the same name, GitHub uses the most specific variable. For example, an environment variable defined in a step will override job and workflow environment variables with the same name, while the step executes. An environment variable defined for a job will override a workflow variable with the same name, while the job executes.

YAML
name:HiMascoton:pushenv:mascot:Monasuper_duper_var:totally_awesomejobs:windows_job:runs-on:windows-lateststeps:-run:echo'Hi ${{ env.mascot }}'# Hi Mona-run:echo'Hi ${{ env.mascot }}'# Hi Octocatenv:mascot:Octocatlinux_job:runs-on:ubuntu-latestenv:mascot:Tuxsteps:-run:echo'Hi ${{ env.mascot }}'# Hi Tux

vars context

Thevars context contains custom configuration variables set at the organization, repository, and environment levels. For more information about defining configuration variables for use in multiple workflows, seeStore information in variables.

Example contents of thevars context

The contents of thevars context is a mapping of configuration variable names to their values.

{"mascot":"Mona"}

Example usage of thevars context

This example workflow shows how configuration variables set at the repository, environment, or organization levels are automatically available using thevars context.

Note

Configuration variables at the environment level are automatically available after their environment is declared by the runner.

If a configuration variable has not been set, the return value of a context referencing the variable will be an empty string.

The following example shows using configuration variables with thevars context across a workflow. Each of the following configuration variables have been defined at the repository, organization, or environment levels.

YAML
on:workflow_dispatch:env:# Setting an environment variable with the value of a configuration variableenv_var:${{vars.ENV_CONTEXT_VAR}}jobs:display-variables:name:${{vars.JOB_NAME}}# You can use configuration variables with the `vars` context for dynamic jobsif:${{vars.USE_VARIABLES=='true'}}runs-on:${{vars.RUNNER}}environment:${{vars.ENVIRONMENT_STAGE}}steps:-name:Usevariablesrun:|        echo "repository variable : $REPOSITORY_VAR"        echo "organization variable : $ORGANIZATION_VAR"        echo "overridden variable : $OVERRIDE_VAR"        echo "variable from shell environment : $env_var"env:REPOSITORY_VAR:${{vars.REPOSITORY_VAR}}ORGANIZATION_VAR:${{vars.ORGANIZATION_VAR}}OVERRIDE_VAR:${{vars.OVERRIDE_VAR}}-name:${{vars.HELLO_WORLD_STEP}}if:${{vars.HELLO_WORLD_ENABLED=='true'}}uses:actions/hello-world-javascript-action@mainwith:who-to-greet:${{vars.GREET_NAME}}

job context

Thejob context contains information about the currently running job.

Property nameTypeDescription
jobobjectThis context changes for each job in a workflow run. You can access this context from any step in a job. This object contains all the properties listed below.
job.containerobjectInformation about the job's container. For more information about containers, seeWorkflow syntax for GitHub Actions.
job.container.idstringThe ID of the container.
job.container.networkstringThe ID of the container network. The runner creates the network used by all containers in a job.
job.servicesobjectThe service containers created for a job. For more information about service containers, seeWorkflow syntax for GitHub Actions.
job.services.<service_id>.idstringThe ID of the service container.
job.services.<service_id>.networkstringThe ID of the service container network. The runner creates the network used by all containers in a job.
job.services.<service_id>.portsobjectThe exposed ports of the service container.
job.statusstringThe current status of the job. Possible values aresuccess,failure, orcancelled.

Example contents of thejob context

This examplejob context uses a PostgreSQL service container with mapped ports. If there are no containers or service containers used in a job, thejob context only contains thestatus property.

{"status":"success","container":{"network":"github_network_53269bd575974817b43f4733536b200c"},"services":{"postgres":{"id":"60972d9aa486605e66b0dad4abb638dc3d9116f566579e418166eedb8abb9105","ports":{"5432":"49153"},"network":"github_network_53269bd575974817b43f4733536b200c"}}}

Example usage of thejob context

This example workflow configures a PostgreSQL service container, and automatically maps port 5432 in the service container to a randomly chosen available port on the host. Thejob context is used to access the number of the port that was assigned on the host.

YAML
name:PostgreSQLServiceExampleon:pushjobs:postgres-job:runs-on:ubuntu-latestservices:postgres:image:postgresenv:POSTGRES_PASSWORD:postgresoptions:--health-cmdpg_isready--health-interval10s--health-timeout5s--health-retries5ports:# Maps TCP port 5432 in the service container to a randomly chosen available port on the host.-5432steps:-run:pg_isready-hlocalhost-p${{job.services.postgres.ports[5432]}}-run:echo"Run tests against Postgres"

jobs context

Thejobs context is only available in reusable workflows, and can only be used to set outputs for a reusable workflow. For more information, seeReuse workflows.

Property nameTypeDescription
jobsobjectThis is only available in reusable workflows, and can only be used to set outputs for a reusable workflow. This object contains all the properties listed below.
jobs.<job_id>.resultstringThe result of a job in the reusable workflow. Possible values aresuccess,failure,cancelled, orskipped.
jobs.<job_id>.outputsobjectThe set of outputs of a job in a reusable workflow.
jobs.<job_id>.outputs.<output_name>stringThe value of a specific output for a job in a reusable workflow.

Example contents of thejobs context

This examplejobs context contains the result and outputs of a job from a reusable workflow run.

{"example_job":{"result":"success","outputs":{"output1":"hello","output2":"world"}}}

Example usage of thejobs context

This example reusable workflow uses thejobs context to set outputs for the reusable workflow. Note how the outputs flow up from the steps, to the job, then to theworkflow_call trigger. For more information, seeReuse workflows.

YAML
name:Reusableworkflowon:workflow_call:# Map the workflow outputs to job outputsoutputs:firstword:description:"The first output string"value:${{jobs.example_job.outputs.output1}}secondword:description:"The second output string"value:${{jobs.example_job.outputs.output2}}jobs:example_job:name:Generateoutputruns-on:ubuntu-latest# Map the job outputs to step outputsoutputs:output1:${{steps.step1.outputs.firstword}}output2:${{steps.step2.outputs.secondword}}steps:-id:step1run:echo"firstword=hello">>$GITHUB_OUTPUT-id:step2run:echo"secondword=world">>$GITHUB_OUTPUT

steps context

Thesteps context contains information about the steps in the current job that have anid specified and have already run.

Property nameTypeDescription
stepsobjectThis context changes for each step in a job. You can access this context from any step in a job. This object contains all the properties listed below.
steps.<step_id>.outputsobjectThe set of outputs defined for the step. For more information, seeMetadata syntax reference.
steps.<step_id>.conclusionstringThe result of a completed step aftercontinue-on-error is applied. Possible values aresuccess,failure,cancelled, orskipped. When acontinue-on-error step fails, theoutcome isfailure, but the finalconclusion issuccess.
steps.<step_id>.outcomestringThe result of a completed step beforecontinue-on-error is applied. Possible values aresuccess,failure,cancelled, orskipped. When acontinue-on-error step fails, theoutcome isfailure, but the finalconclusion issuccess.
steps.<step_id>.outputs.<output_name>stringThe value of a specific output.

Example contents of thesteps context

This examplesteps context shows two previous steps that had anid specified. The first step had theid namedcheckout, the secondgenerate_number. Thegenerate_number step had an output namedrandom_number.

{"checkout":{"outputs":{},"outcome":"success","conclusion":"success"},"generate_number":{"outputs":{"random_number":"1"},"outcome":"success","conclusion":"success"}}

Example usage of thesteps context

This example workflow generates a random number as an output in one step, and a later step uses thesteps context to read the value of that output.

YAML
name:Generaterandomfailureon:pushjobs:randomly-failing-job:runs-on:ubuntu-lateststeps:-name:Generate0or1id:generate_numberrun:echo"random_number=$(($RANDOM % 2))">>$GITHUB_OUTPUT-name:Passorfailrun:|          if [[ ${{ steps.generate_number.outputs.random_number }} == 0 ]]; then exit 0; else exit 1; fi

runner context

Therunner context contains information about the runner that is executing the current job.

Property nameTypeDescription
runnerobjectThis context changes for each job in a workflow run. This object contains all the properties listed below.
runner.namestringThe name of the runner executing the job. This name may not be unique in a workflow run as runners at the repository and organization levels could use the same name.
runner.osstringThe operating system of the runner executing the job. Possible values areLinux,Windows, ormacOS.
runner.archstringThe architecture of the runner executing the job. Possible values areX86,X64,ARM, orARM64.
runner.tempstringThe path to a temporary directory on the runner. This directory is emptied at the beginning and end of each job. Note that files will not be removed if the runner's user account does not have permission to delete them.
runner.tool_cachestringThe path to the directory containing preinstalled tools for GitHub-hosted runners. For more information, seeAbout GitHub-hosted runners.
runner.debugstringThis is set only ifdebug logging is enabled, and always has the value of1. It can be useful as an indicator to enable additional debugging or verbose logging in your own job steps.
runner.environmentstringThe environment of the runner executing the job. Possible values are:github-hosted for GitHub-hosted runners provided by GitHub, andself-hosted for self-hosted runners configured by the repository owner.

Example contents of therunner context

The following example context is from a Linux GitHub-hosted runner.

{"os":"Linux","arch":"X64","name":"GitHub Actions 2","tool_cache":"/opt/hostedtoolcache","temp":"/home/runner/work/_temp"}

Example usage of therunner context

This example workflow uses therunner context to set the path to the temporary directory to write logs, and if the workflow fails, it uploads those logs as artifact.

YAML
name:Buildon:pushjobs:build:runs-on:ubuntu-lateststeps:-uses:actions/checkout@v4-name:Buildwithlogsrun:|          mkdir ${{ runner.temp }}/build_logs          echo "Logs from building" > ${{ runner.temp }}/build_logs/build.logs          exit 1-name:Uploadlogsonfailif:${{failure()}}uses:actions/upload-artifact@v4with:name:Buildfailurelogspath:${{runner.temp}}/build_logs

secrets context

Thesecrets context contains the names and values of secrets that are available to a workflow run. Thesecrets context is not available for composite actions due to security reasons. If you want to pass a secret to a composite action, you need to do it explicitly as an input. For more information about secrets, seeUsing secrets in GitHub Actions.

GITHUB_TOKEN is a secret that is automatically created for every workflow run, and is always included in thesecrets context. For more information, seeUse GITHUB_TOKEN in workflows.

Warning

If a secret is used in a workflow job, GitHub automatically redacts secrets printed to the log. You should avoid printing secrets to the log intentionally.

Property nameTypeDescription
secretsobjectThis context is the same for each job in a workflow run. You can access this context from any step in a job. This object contains all the properties listed below.
secrets.GITHUB_TOKENstringAutomatically created token for each workflow run. For more information, seeUse GITHUB_TOKEN in workflows.
secrets.<secret_name>stringThe value of a specific secret.

Example contents of thesecrets context

The following example contents of thesecrets context shows the automaticGITHUB_TOKEN, as well as two other secrets available to the workflow run.

{"github_token":"***","NPM_TOKEN":"***","SUPERSECRET":"***"}

Example usage of thesecrets context

This example workflow uses theGitHub CLI, which requires theGITHUB_TOKEN as the value for theGH_TOKEN input parameter:

YAML
name:Opennewissueon:workflow_dispatchjobs:open-issue:runs-on:ubuntu-latestpermissions:contents:readissues:writesteps:-run:|          gh issue --repo ${{ github.repository }} \            create --title "Issue title" --body "Issue body"env:GH_TOKEN:${{secrets.GITHUB_TOKEN}}

strategy context

For workflows with a matrix, thestrategy context contains information about the matrix execution strategy for the current job.

Property nameTypeDescription
strategyobjectThis context changes for each job in a workflow run. You can access this context from any job or step in a workflow. This object contains all the properties listed below.
strategy.fail-fastbooleanWhen this evaluates totrue, all in-progress jobs are canceled if any job in a matrix fails. For more information, seeWorkflow syntax for GitHub Actions.
strategy.job-indexnumberThe index of the current job in the matrix.Note: This number is a zero-based number. The first job's index in the matrix is0.
strategy.job-totalnumberThe total number of jobs in the matrix.Note: This numberis not a zero-based number. For example, for a matrix with four jobs, the value ofjob-total is4.
strategy.max-parallelnumberThe maximum number of jobs that can run simultaneously when using amatrix job strategy. For more information, seeWorkflow syntax for GitHub Actions.

Example contents of thestrategy context

The following example contents of thestrategy context is from a matrix with four jobs, and is taken from the final job. Note the difference between the zero-basedjob-index number, andjob-total which is not zero-based.

{"fail-fast":true,"job-index":3,"job-total":4,"max-parallel":4}

Example usage of thestrategy context

This example workflow uses thestrategy.job-index property to set a unique name for a log file for each job in a matrix.

YAML
name:Teststrategyon:pushjobs:test:runs-on:ubuntu-lateststrategy:matrix:test-group: [1,2]node: [14,16]steps:-run:echo"Mock test logs">test-job-${{strategy.job-index}}.txt-name:Uploadlogsuses:actions/upload-artifact@v4with:name:Buildlogforjob${{strategy.job-index}}path:test-job-${{strategy.job-index}}.txt

matrix context

For workflows with a matrix, thematrix context contains the matrix properties defined in the workflow file that apply to the current job. For example, if you configure a matrix with theos andnode keys, thematrix context object includes theos andnode properties with the values that are being used for the current job.

There are no standard properties in thematrix context, only those which are defined in the workflow file.

Property nameTypeDescription
matrixobjectThis context is only available for jobs in a matrix, and changes for each job in a workflow run. You can access this context from any job or step in a workflow. This object contains the properties listed below.
matrix.<property_name>stringThe value of a matrix property.

Example contents of thematrix context

The following example contents of thematrix context is from a job in a matrix that has theos andnode matrix properties defined in the workflow. The job is executing the matrix combination of anubuntu-latest OS and Node.js version16.

{"os":"ubuntu-latest","node":16}

Example usage of thematrix context

This example workflow creates a matrix withos andnode keys. It uses thematrix.os property to set the runner type for each job, and uses thematrix.node property to set the Node.js version for each job.

YAML
name:Testmatrixon:pushjobs:build:runs-on:${{matrix.os}}strategy:matrix:os: [ubuntu-latest,windows-latest]node: [14,16]steps:-uses:actions/setup-node@v4with:node-version:${{matrix.node}}-name:Outputnodeversionrun:node--version

needs context

Theneeds context contains outputs from all jobs that are defined as a direct dependency of the current job. Note that this doesn't include implicitly dependent jobs (for example, dependent jobs of a dependent job). For more information on defining job dependencies, seeWorkflow syntax for GitHub Actions.

Property nameTypeDescription
needsobjectThis context is only populated for workflow runs that have dependent jobs, and changes for each job in a workflow run. You can access this context from any job or step in a workflow. This object contains all the properties listed below.
needs.<job_id>objectA single job that the current job depends on.
needs.<job_id>.outputsobjectThe set of outputs of a job that the current job depends on.
needs.<job_id>.outputs.<output name>stringThe value of a specific output for a job that the current job depends on.
needs.<job_id>.resultstringThe result of a job that the current job depends on. Possible values aresuccess,failure,cancelled, orskipped.

Example contents of theneeds context

The following example contents of theneeds context shows information for two jobs that the current job depends on.

{"build":{"result":"success","outputs":{"build_id":"123456"}},"deploy":{"result":"failure","outputs":{}}}

Example usage of theneeds context

This example workflow has three jobs: abuild job that does a build, adeploy job that requires thebuild job, and adebug job that requires both thebuild anddeploy jobs and runs only if there is a failure in the workflow. Thedeploy job also uses theneeds context to access an output from thebuild job.

YAML
name:Buildanddeployon:pushjobs:build:runs-on:ubuntu-latestoutputs:build_id:${{steps.build_step.outputs.build_id}}steps:-name:Buildid:build_steprun:echo"build_id=$RANDOM">>$GITHUB_OUTPUTdeploy:needs:buildruns-on:ubuntu-lateststeps:-run:echo"Deploying build ${{ needs.build.outputs.build_id }}"debug:needs: [build,deploy]runs-on:ubuntu-latestif:${{failure()}}steps:-run:echo"Failed to build and deploy"

inputs context

Theinputs context contains input properties passed to an action, to a reusable workflow, or to a manually triggered workflow. For reusable workflows, the input names and types are defined in theworkflow_call event configuration of a reusable workflow, and the input values are passed fromjobs.<job_id>.with in an external workflow that calls the reusable workflow. For manually triggered workflows, the inputs are defined in theworkflow_dispatch event configuration of a workflow.

The properties in theinputs context are defined in the workflow file. They are only available in areusable workflow or in a workflow triggered by theworkflow_dispatch event

Property nameTypeDescription
inputsobjectThis context is only available in areusable workflow or in a workflow triggered by theworkflow_dispatch event. You can access this context from any job or step in a workflow. This object contains the properties listed below.
inputs.<name>string ornumber orboolean orchoiceEach input value passed from an external workflow.

Example contents of theinputs context

The following example contents of theinputs context is from a workflow that has defined thebuild_id,deploy_target, andperform_deploy inputs.

{"build_id":123456768,"deploy_target":"deployment_sys_1a","perform_deploy":true}

Example usage of theinputs context in a reusable workflow

This example reusable workflow uses theinputs context to get the values of thebuild_id,deploy_target, andperform_deploy inputs that were passed to the reusable workflow from the caller workflow.

YAML
name:Reusabledeployworkflowon:workflow_call:inputs:build_id:required:truetype:numberdeploy_target:required:truetype:stringperform_deploy:required:truetype:booleanjobs:deploy:runs-on:ubuntu-latestif:${{inputs.perform_deploy}}steps:-name:Deploybuildtotargetrun:echo"Deploying build:${{ inputs.build_id }} to target:${{ inputs.deploy_target }}"

Example usage of theinputs context in a manually triggered workflow

This example workflow triggered by aworkflow_dispatch event uses theinputs context to get the values of thebuild_id,deploy_target, andperform_deploy inputs that were passed to the workflow.

YAML
on:workflow_dispatch:inputs:build_id:required:truetype:stringdeploy_target:required:truetype:stringperform_deploy:required:truetype:booleanjobs:deploy:runs-on:ubuntu-latestif:${{inputs.perform_deploy}}steps:-name:Deploybuildtotargetrun:echo"Deploying build:${{ inputs.build_id }} to target:${{ inputs.deploy_target }}"

Further reading


[8]ページ先頭

©2009-2025 Movatter.jp