Automation Environment Variables
In your automation script, you have access to a number of Automation environment variables. Use these variables to get data about your execution context: current Git branch name and Git revision number, Space URL, and so on. Don't confuse Automation environment variables with the container environment variables (set with job.container.env
).
If you run Kotlin code inside the kotlinScript
block, you can get variable values directly or using the API commands:
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
, anddocker.beforeBuildScript
in acontainer
. On this phase, Automation environment variables are resolved inside the specified container. This means that you can access Automation environment variables only inside thekotlinScript
,shellScript
, andbeforeBuildScript
items .
General
Variable | API method | Description |
---|---|---|
JB_SPACE_API_URL | spaceUrl(): String | The URL of your JetBrains Space instance. For example: mycompany.jetbrains.space |
Authentication
Variable | API method | Description |
---|---|---|
JB_SPACE_CLIENT_ID JB_SPACE_CLIENT_SECRET | spaceClientId(): String spaceClientSecret(): String | Temporary OAuth 2.0 credentials issued to the current script. The script uses them to authenticate in various Space modules. For example, you may need them to authenticate in a Packages repository in order to publish script artifacts. |
Project settings
Variable | API method | Description |
---|---|---|
JB_SPACE_GIT_REVISION | gitRevision(): String | The current Git revision number |
JB_SPACE_GIT_BRANCH | gitBranch(): String | The current Git branch name |
JB_SPACE_PROJECT_ID | projectId(): String | The ID of the current project |
JB_SPACE_PROJECT_KEY | projectKey(): String | The key of the current project |
JB_SPACE_GIT_REPOSITORY_NAME | gitRepositoryName(): String | The name of the current Git repository (the one that contains the currently running .space.kts file) |
Automation
Variable | API method | Description |
---|---|---|
JB_SPACE_EXECUTION_NUMBER | executionNumber(): String | The current build number. For example, you can use it to generate application version number. Learn more |
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
: