This action manages environment variables. It can:
- Load custom variables.
- List environment variables which are present on the GitHub runner.
- Load variables from a json file into a GitHub runners environment variables. Will also load variables from files referenced by the main json file.
This action addresses the need for defining variables as code, which can be reused for all deployments in the repo in addition to using the secrets and environments defined for the repo.
Input name | Default | Required | Description | Allowed values |
---|---|---|---|---|
Load |
true |
No | Load environment variables from variable file to runner. | true /false |
List |
false |
No | List environment variables on runner | true /false |
VariableFilePath |
'' | Yes | Path to a variables json file. | Relative or absolute path to a json file. |
This action uses environment variables with input overrides. For more info please read our article on Input handling
Takes a relative or absolute path to a json file containing variables.
If VariableFilePath
is not provided with this action, the environment variable called VariableFilePath
is checked and used instead.
If neither are present, the variable loader will not be invoked and the script will exit with a failure.
{
"MascotName": "Super Cat",
"Superpower": "Lazer shooting eyes",
"VariableFilePaths": [
"./Folder/Vars.json"
"./GlobalVars.json"
]
}
Referenced variables json files can be loaded by using the VariableFilePaths
item. This item takes an array of paths to other files.
Referenced files are loaded before the variables in the first file, leading to variables in referenced files being overridden by the first file.
Lets take a look at an example of 3 variables files, A.json
, B.json
and C.json
. Each of the files contains the letters in a variable called Letter
. File A.json
also has a VariableFilePaths
array with file B
and C
.
The loading process would be as following:
- Runner reads file content of file
A.json
. - Process files in
VariableFilePaths
from fileA.json
.- Runner reads file content of file
B.json
.- Process files in
VariableFilePaths
- It's empty, so the action continues. - Load variables of file
B.json
.Letter = B
.
- Process files in
- Runner reads file content of file
C.json
.- Process files in
VariableFilePaths
- It's empty, so the action continues. - Load variables of file
C.json
.Letter = C
.
- Process files in
- Runner reads file content of file
- Load variables in file
A.json
.Letter = A
.
We see here that the last write wins and Letter
has been overridden twice, and is A
at the end of the loading process.
To see this in action, check out the "Load and list variables" step in the Action-Test workflow.
N/A
This module can load variables into the environment variables of the runner. The variable names and values of these depend on the variable file which is loaded. When creating the environment variables, be sure to follow the recommended naming convention from GitHub when doing so.
In addition there are some missing variables which a GitHub runner should have.
Variable name | Description |
---|---|
build |
A timestamp from when this action is run, following the format YYYYMMDDhhmmss . Can be used for constructing semver version for builds, adding to the patch segment of the version. |
GITHUB_REPOSITORY_NAME |
The name of the repository where the workflow is being triggered from. |
name: Test-Workflow
on: [push]
env:
VariableFilePath: Folder/greenVars.json
jobs:
Variables:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: List variables
uses: AzActions/Variables@v1
with:
List: true
# Will list environment variables on the runner
- name: Load variables
uses: AzActions/Variables@v1
# Will load based on env.VariableFilePath, 'Folder/greenVars.json'
- name: Load and list variables
uses: AzActions/Variables@v1
with:
Load: true
List: true
VariableFilePath: Folder/blueVars.json
# Will load based on input.VariableFilePath, 'Folder/blueVars.json'.
- AzActions/AzUtilities
- If you are looking to load a variable file, run action/checkout first.
This project welcomes contributions and suggestions. Please review How to contribute on our AzActions page.