About variables
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 GitHub sets automatically. For more information, see "Default environment variables".
You can set a custom variable in two ways.
- To define an environment variable for use in a single workflow, you can use the
envkey in the workflow file. For more information, see "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".
Warning: By default, variables render unmasked in your build outputs. If you need greater security for sensitive information, such as passwords, use encrypted secrets instead. For more information, see "Encrypted secrets".
Defining environment variables for a single workflow
To set a custom environment variable for a single workflow, you can define it using the env key in the workflow file. The scope of a custom variable set by this method is limited to the element in which it is defined. You can define variables that are scoped for:
- The entire workflow, by using
envat the top level of the workflow file. - The contents of a job within a workflow, by using
jobs.<job_id>.env. - A specific step within a job, by using
jobs.<job_id>.steps[*].env.
name: Greeting on variable day
on:
workflow_dispatch
env:
DAY_OF_WEEK: Monday
jobs:
greeting_job:
runs-on: ubuntu-latest
env:
Greeting: Hello
steps:
- name: "Say Hello Mona it's Monday"
run: echo "$Greeting $First_Name. Today is $DAY_OF_WEEK!"
env:
First_Name: MonaYou can access env variable values using runner environment variables or using contexts. The example above shows three custom variables being used as environment variables in an echo command: $DAY_OF_WEEK, $Greeting, and $First_Name. The values for these variables are set, and scoped, at the workflow, job, and step level respectively. For more information on accessing variable values using contexts, see "Using contexts to access variable values."
Because runner environment variable interpolation is done after a workflow job is sent to a runner machine, you must use the appropriate syntax for the shell that's used on the runner. In this example, the workflow specifies ubuntu-latest. By default, Linux runners use the bash shell, so you must use the syntax $NAME. If the workflow specified a Windows runner, you would use the syntax for PowerShell, $env:NAME. For more information about shells, see "Workflow syntax for GitHub Actions."
Naming conventions for environment variables
When you set an environment variable, you cannot use any of the default environment variable names. For a complete list of default environment variables, see "Default environment variables" below. If you attempt to override the value of one of these default variables, the assignment is ignored.
Any new variables you set that point to a location on the filesystem should have a _PATH suffix. The GITHUB_ENV and GITHUB_WORKSPACE default variables are exceptions to this convention.
Note: You can list the entire set of environment variables that are available to a workflow step by using run: env in a step and then examining the output for the step.
Defining configuration variables for multiple workflows
Note: Configuration variables for GitHub Actions are in beta and subject to change.
You can create configuration variables for use across multiple workflows, and can define them at either the organization, repository, or environment level.
For example, you can use configuration variables to set default values for parameters passed to build tools at an organization level, but then allow repository owners to override these parameters on a case-by-case basis.
When you define configuration variables, they are automatically available in the vars context. For more information, see "Using the vars context to access configuration variable values".
Configuration variable precedence
If a variable with the same name exists at multiple levels, the variable at the lowest level takes precedence. For example, if an organization-level variable has the same name as a repository-level variable, then the repository-level variable takes precedence. Similarly, if an organization, repository, and environment all have a variable with the same name, the environment-level variable takes precedence.
For reusable workflows, the variables from the caller workflow's repository are used. Variables from the repository that contains the called workflow are not made available to the caller workflow.
Naming conventions for configuration variables
The following rules apply to configuration variable names:
- Names can only contain alphanumeric characters (
[a-z],[A-Z],[0-9]) or underscores (_). Spaces are not allowed. - Names must not start with the
GITHUB_prefix. - Names must not start with a number.
- Names are not case-sensitive.
- Names must be unique at the level they are created at.
Creating configuration variables for a repository
To create secrets or variables for a personal account repository, you must be the repository owner. To create secrets or variables for an organization repository, you must have admin access.
-
On GitHub.com, navigate to the main page of the repository.
-
Under your repository name, click Settings. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings.

-
In the "Security" section of the sidebar, select Secrets and variables, then click Actions.
-
Click the Variables tab.

-
Click New repository variable.
-
In the Name field, enter a name for your variable.
-
In the Value field, enter the value for your variable.
-
Click Add variable.
Creating configuration variables for an environment
To create secrets or variables for an environment in a personal account repository, you must be the repository owner. To create secrets or variables for an environment in an organization repository, you must have admin access.
-
On GitHub.com, navigate to the main page of the repository.
-
Under your repository name, click Settings. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings.

-
In the left sidebar, click Environments.
-
Click on the environment that you want to add a variable to.
-
Under Environment variables, click Add variable.
-
In the Name field, enter a name for your variable.
-
In the Value field, enter the value for your variable.
-
Click Add variable.
Creating configuration variables for an organization
When creating a secret or variable in an organization, you can use a policy to limit access by repository. For example, you can grant access to all repositories, or limit access to only private repositories or a specified list of repositories.
To create secrets or variables at the organization level, you must have admin access.
-
On GitHub.com, navigate to the main page of the organization.
-
Under your organization name, click Settings.

-
In the "Security" section of the sidebar, select Secrets and variables, then click Actions.
-
Click the Variables tab.

-
Click New organization variable.
-
In the Name field, enter a name for your variable.
-
In the Value field, enter the value for your variable.
-
From the Repository access dropdown list, choose an access policy.
-
Click Add variable.
Limits for configuration variables
Individual variables are limited to 48 KB in size.
You can store up to 1,000 organization variables, 500 variables per repository, and 100 variables per environment. The total combined size limit for organization and repository variables is 256 KB per workflow run.
A workflow created in a repository can access the following number of variables:
- Up to 500 repository variables, if the total size of repository variables is less than 256 KB. If the total size of repository variables exceeds 256 KB, only the repository variables that fall below the limit will be available (as sorted alphabetically by variable name).
- Up to 1,000 organization variables, if the total combined size of repository and organization variables is less than 256 KB. If the total combined size of organization and repository variables exceeds 256 KB, only the organization variables that fall below that limit will be available (after accounting for repository variables and as sorted alphabetically by variable name).
- Up to 100 environment-level variables.
Note: Environment-level variables do not count toward the 256 KB total size limit. If you exceed the combined size limit for repository and organization variables and still need additional variables, you can use an environment and define additional variables in the environment.
Using contexts to access variable values
Contexts are a way to access information about workflow runs, variables, runner environments, jobs, and steps. For more information, see "Contexts". There are many other contexts that you can use for a variety of purposes in your workflows. For details of where you can use specific contexts within a workflow, see "Contexts."
You can access environment variable values using the env context and configuration variable values using the vars context.
Using the env context to access environment variable values
In addition to runner environment variables, GitHub Actions allows you to set and read env key values using contexts. Environment variables and contexts are intended for use at different points in the workflow.
Runner environment variables are always interpolated on the runner machine. However, parts of a workflow are processed by GitHub Actions and are not sent to the runner. You cannot use environment variables in these parts of a workflow file. Instead, you can use contexts. For example, an if conditional, which determines whether a job or step is sent to the runner, is always processed by GitHub Actions. You can use a context in an if conditional statement to access the value of an variable.