| PowerShell | `$env:variable` (primary) or `$variable` |
| Windows Batch | `%variable%` |
To access environment variables in bash, prefix the variable name with (`$`):
### Bash
To access environment variables in **bash**, prefix the variable name with (`$`):
```yaml
job_name:
...
...
@@ -256,32 +258,54 @@ job_name:
-echo $CI_JOB_ID
```
To access environment variables in **Windows Batch**, surround the variable
with (`%`):
### PowerShell
To access environment variables in a **Windows PowerShell** environment, prefix
the variable name with (`$env:`). For environment variables set by GitLab CI, including those set by [`variables`](https://gitlab.com/gitlab-org/gitlab/blob/master/doc/ci/yaml/README.md#variables)
parameter, they can also be accessed by prefixing the variable name with (`$`)
as of [GitLab Runner 1.0.0](https://gitlab.com/gitlab-org/gitlab-runner/-/commit/abc44bb158008cd3a49c0d8173717c38dadb29ae#47afd7e8f12afdb8f0246262488f24e6dd071a22).
System set environment variables however must be accessed using (`$env:`).
```yaml
job_name:
script:
-echo %CI_JOB_ID%
-echo $env:CI_JOB_ID
-echo $CI_JOB_ID
-echo $env:PATH
```
To access environment variables in a **Windows PowerShell** environment, prefix
the variable name with (`$env:`):
In [some cases](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4115#note_157692820)
environment variables may need to be surrounded by quotes to expand properly: