Automation Environment Variables
In your automation script, you have access to a number of Automation environment variables. Use these variables to get data about the script run context: for example, current Git branch name and Git revision number, Space URL, and so on.
If you want to get environment variables in a shell script, note that you need to escape the $
symbol in a Kotlin way, for example, ${'$'}JB_SPACE_API_URL
. Also, you can get some of the Automation environment variables using the the API commands (only inside the kotlinScript
block). For example:
When does Automation resolve environment variables
The work of an Automation script consists of two phases:
Script compilation: Automation checks the
.space.kts
file for errors and compiles the necessary script parts. This phase is performed in a separate container that cannot be anyhow accessed from within the script. Automation environment variables are not resolved on this phase.Script run: Automation runs the content of
kotlinScript
,shellScript
, andkaniko.beforeBuildScript
. On this phase, Automation environment variables are resolved inside the specified run environment. This means that you can access Automation environment variables only inside thekotlinScript
,shellScript
, andbeforeBuildScript
blocks.
General
Variable | API method | Description |
---|---|---|
|
| The URL of your JetBrains Space instance. For example: mycompany.jetbrains.space |
Authentication
Variable | API method | Description |
---|---|---|
|
| Temporary OAuth 2.0 access token issued to the current script. The script can use it to authorize in various Space modules. For example, you can use it to authorize the script in a Packages repository in order to publish build artifacts. |
|
| As an alternative to an access token, the script can authorize with temporary OAuth 2.0 credentials. |
Project settings
Variable | API method | Description |
---|---|---|
| – | An absolute path to the parent directory with the step data. |
| – | An absolute path to the project working directory. Learn more about directory structure in containers and hosted workers. |
| – | An absolute path to the external storage used for file sharing. |
|
| The current Git revision number |
|
| The current Git branch name |
|
| The ID of the current project |
|
| The key of the current project |
|
| The name of the current Git repository (the one that contains the currently running |
Automation
Variable | API method | Description |
---|---|---|
|
| The current job execution number (build number). For example, you can use it to generate application version number. Learn more |
|
| The unique ID of the current job execution (build). You can use it to refer to a particular build using the Space API. |
|
| A link to the current job execution. |
Self-hosted and cloud workers
Variable | API method | Description |
---|---|---|
| – | The URL of the JetBrains Space instance assigned to the worker. For example: mycompany.jetbrains.space |
| – | An authorization token issued to the worker. The worker uses it to authenticate in Space. |
| – | The path to the directory where the script downloads all required data: project sources, file share, and Automation-specific data. |
| – | A host name of the worker. |
| – | The system resources available on the host machine that runs the worker agent: CPU cores in mCPU, and RAM in MB. |
Example. Use environment variables to generate a product version
For example, you want to generate a Docker container tag based on the current branch name and the job run number like version-0.123-mybranch
: