DSL Reference
The Automation DSL is a domain specific language whose goal is to help you write Space automation scripts. The DSL is based on Kotlin programming language. This means that you can use Kotlin data types and language constructs inside your scripts.
job
job
is a defined task consisting of steps.
job(name: String, init: Task.() -> Unit)
| |
|
For example:
job.requirements
requirements
specifies requirements to the job run environment.
requirements(init: ScriptJobRequirementsBuilder.() -> Unit)
|
For example:
job.container
container
runs a container and executes the specified command or script inside this container.
container(image: String, init: Container.() -> Unit = {})
container(displayName: String?, image: String, init: Container.() -> Unit = {})
| |||||||||||||||||||||
| |||||||||||||||||||||
|
For example:
job.container.args
If entrypoint
is specified, args
provides arguments for the entrypoint
command. Otherwise, args
provides arguments for the default image command (for example, set by ENTRYPOINT
). Each argument must be a separate string in the args
array. If you specify more than one args
, only the last one will take effect.
args(vararg args: String)
For example:
job.container.cache
cache
speeds up builds by caching project dependencies in a file repository. Learn more
cache(init: FileCache.() -> Unit)
|
For example:
job.container.dockerRegistryConnections
dockerRegistryConnections
defines Docker registries to log into before running the container
step. The step can use an image from these Docker registries. This makes possible using images from registries that require authentication. Note that the corresponding registry connections should first be declared in your project settings. Learn more
dockerRegistryConnections(init: DockerRegistryConnections.() -> Unit)
Inside dockerRegistryConnections
, use the unary +
operator to add connections.
For example:
job.container.entrypoint
entrypoint
runs the specified command overriding the default image command. This is equivalent to Docker's ENTRYPOINT
. Command arguments must be provided as separate strings in the args
array . If you specify more than one entrypoint
, only the last one will take effect.
entrypoint(entryPoint: String)
For example:
job.container.env
env
lets you set environment variables in a container. Note that you can get various information about the current run context with the help of Automation environment variables.
env = Environment()
The
|
For example:
job.container.fileArtifacts
fileArtifacts
uploads file artifacts generated by the step to a file repository. Learn more
fileArtifacts(init: FileArtifact.() -> Unit)
|
For example:
job.container.fileInput
fileInput
populates a file from one of the specified sources. Learn more
fileInput(init: FileInput.() -> Unit)
|
For example:
job.container.kotlinScript
kotlinScript
runs arbitrary Kotlin code. If you specify more than one kotlinScript
, only the last one will be run. Note that in order to run a Kotlin script, the container image you use must include JRE/JDK 11 or later.
kotlinScript(init: ProcessKotlinScript.(ScriptAPI) -> Unit)
For example:
kotlinScript
provides access to various APIs. The APIs let you work with particular Space modules or with build tools like Gradle. Currently, the following APIs are available:
Function | Returns | Description |
---|---|---|
|
| Runs Gradle commands using the Gradle wrapper from the project sources. For example: |
|
| Returns the URL of your Space instance. |
|
| Returns the name of the current Git branch. For example, |
|
| Returns the current Git revision number. For example, |
|
| Returns the number of the current Automation script execution. You can use this number, for example, to generate the application version number. |
|
| Returns the ID and the key of the current project. |
|
| Returns the current client ID and secret. These are temporary OAuth 2.0 credentials issued to the current script. The script uses them to authenticate in various Space modules. For example, you might need it to authenticate in a Packages repository in order to publish script artifacts. |
|
| Lets you use parameters in Kolin scripts. Learn more |
|
| Lets you use project secrets in Kolin scripts. Learn more |
| Lets you share files between job steps. Learn more | |
| Lets you work with various Space modules. For example:
The Space modules API works through the Space HTTP API. In other words, |
job.container.resources
resources
limits the resources for a container. The default resources constraints are:
2 virtual CPUs
7800 MB memory
resources(init: ExplicitResources.() -> Unit)
|
For example:
job.container.requirements
requirements
specifies requirements to the host machine that should be used to run the step. Specify requirements
in case you want to run a job with a container
step not in the Space cloud but on a specific worker. Learn more
requirements(init: ContainerRequirementsBuilder.() -> Unit)
|
For example:
job.container.runIf
runIf
lets you run a step on a specific condition. If runIf
is an empty string, false
, or code block that returns 0
, the step is skipped. Learn more
runIf(condition: String)
For example:
job.container.service
service
runs a container with a network-accessible service. Learn more
service(image: String, init: Service.() -> Unit = {})
| |||||||||||||||
|
For example:
job.container.shellScript
shellScript
runs the provided shell script.
shellScript(init: ContainerShellScript.() -> Unit)
|
For example:
Note that marking the script file as executable with chmod +x
is not necessary: Automation automatically sets the 'executable' flag for the script file specified in location
.
job.host
host
executes the specified script directly on a host machine. This could be a hosted or a cloud worker.
host(displayName: String? = null, init: Host.() -> Unit = {})
| |||||||||
|
For example:
job.host.cache
cache
speeds up builds by caching project dependencies in a file repository. Learn more
cache(init: FileCache.() -> Unit)
|
For example:
job.host.dockerBuildPush
dockerBuildPush
is a special helper block used to build and publish Docker images in self-hosted or Space Cloud workers. Learn more
dockerBuildPush(displayName: String? = null, init: DockerBuildPushAction.() -> Unit)
| |||||||||||||||||||||
|
For example:
job.host.dockerRegistryConnections
dockerRegistryConnections
defines Docker registries to log into before running the host
step. This makes possible using registries that require authentication inside the host
step. For example, you can publish images to such repositories. Note that the corresponding registry connections should first be declared in your project settings. Learn more
dockerRegistryConnections(init: DockerRegistryConnections.() -> Unit)
Inside dockerRegistryConnections
, use the unary +
operator to add connections.
For example:
job.host.env
env
lets you set environment variables on the host machine. Note that you can get various information about the current run context with the help of Automation environment variables.
env = Environment()
The
|
For example:
job.host.fileArtifacts
fileArtifacts
uploads file artifacts generated by the step to a file repository. Learn more
fileArtifacts(init: FileArtifact.() -> Unit)
|
For example:
job.host.fileInput
fileInput
populates a file from one of the specified sources. Learn more
fileInput(init: FileInput.() -> Unit)
|
For example:
job.host.kotlinScript
kotlinScript
runs arbitrary Kotlin code.
kotlinScript(init: ProcessKotlinScript.(ScriptAPI) -> Unit)
For example:
kotlinScript
provides access to various APIs. The APIs let you work with particular Space modules or with build tools like Gradle. For the full list of available APIs, refer to job.container.kotlinScript
job.host.requirements
requirements
specifies requirements to the host machine that should be used to run the step. Learn more
requirements(init: HostRequirementsBuilder.() -> Unit)
|
For example:
job.host.requirements.os
os
specifies the required operating system. Automation will route the job only to the worker with the specified operating system. Learn more
os(configure: OSRequirementsBuilder.() -> Unit)
|
For example:
job.host.requirements.resources
resources
specifies requirements to the available system resources (CPU cores and RAM) on the host machine. Automation will route the job only to the worker with the sufficient resources. Learn more
resources(configure: ResourceRequirementsBuidler.() -> Unit)
|
For example:
job.host.requirements.workerTags
workerTags
specifies the required tag(s). Automation will route the job only to the worker that is marked with the specified tag(s). Learn more
workerTags(vararg tags: String)
For example:
job.host.runIf
runIf
lets you run a step on a specific condition. If runIf
is an empty string, false
, or code block that returns 0
, the step is skipped. Learn more
runIf(condition: String)
For example:
job.host.shellScript
shellScript
runs the specified shell script.
shellScript(displayName: String? = null, init: HostShellScript.() -> Unit)
| |||||||||
|
For example:
Note that marking the script file as executable with chmod +x
is not necessary: Automation automatically sets the 'executable' flag for the script file specified in location
.
job.git
git
lets you specify Git repository checkout options. There are two main use-cases of the git
item:
Fetching additional branches and revisions: By default, Automation checks out only the current revision (the one that contains the currently running
.space.kts
script).Checking out additional repositories in projects with multiple repositories: When the build script requires the source code from several repositories at once.
git(init: DefaultGitRepository.() -> Unit = {})
git(repositoryName: String, init: ExternalGitRepository.() -> Unit = {})
| |||||||||||
|
For example:
job.parallel
By default, all container
steps are executed sequentially inside a job
. To execute them in parallel, put them inside a parallel
block.
parallel(init: StepFork.() -> Unit)
|
For example:
job.parallel.sequential
sequential
executes container
steps inside the parallel
block sequentially.
sequential(init: StepSequence.() -> Unit)
|
For example:
job.parameters
The parameters
block let you define job parameters as well as reference project secrets and parameters. Learn more
parameters(init: Parameters.() -> Unit)
|
For example:
job.startOn
The startOn
block contains events that trigger the job
.
startOn(init: Triggers.() -> Unit)
|
For example:
job.startOn.gitPush
gitPush
runs the job after a commit is pushed to the project repository. By default, the gitPush
trigger is enabled for a project. Important: Once you add any other trigger to the job, the gitPush
trigger will be disabled.
gitPush(init: GitPushTrigger.() -> Unit)
|
For example:
job.startOn.schedule
Runs the job on schedule
. For example, once a day at a certain time (UTC timezone).
schedule(init: ScheduleTrigger.() -> Unit)
|
For example:
job.startOn.gitBranchDeleted
gitBranchDeleted
runs the job when a git branch is deleted from the project repository. Works only in the project's default branch (main
).
gitBranchDeleted(init: GitBranchDeletedTrigger.() -> Unit = {})
|
For example:
job.startOn.codeReviewOpened
codeReviewOpened
runs the job when a code review is opened in the project.
codeReviewOpened(init: CodeReviewOpenedTrigger.() -> Unit = {})
|
For example:
job.startOn.codeReviewClosed
codeReviewClosed
runs the job when a code review is closed in the project.
codeReviewClosed(init: CodeReviewClosedTrigger.() -> Unit = {})
|
For example:
job.failOn
The failOn
block contains conditions under which a job
will be considered failed. By default, failed tests and non-zero exit code are failure conditions.
failOn(init: FailureConditions.() -> Unit)
|
job.failOn.nonZeroExitCode
With nonZeroExitCode
, the job is considered failed when it returns nonzero status code. It is a default failure condition.
nonZeroExitCode(init: NonZeroExitCodeCondition.() -> Unit)
|
job.failOn.testFailed
With testFailed
, the job is considered failed if at least one test fails during the job run. It is a default failure condition. Automation detects failed tests by parsing the job output. Currently, only Gradle test output is supported.
testFailed(init: TestFailedCondition.() -> Unit)
|
For example:
job.failOn.outOfMemory
With outOfMemory
, the job is considered failed if any of job containers runs out of memory (based on the OOMKilled
event). It is a default failure condition.
outOfMemory(init: OutOfMemoryCondition.() -> Unit)
|
For example:
job.failOn.timeOut
With timeOut
, the job is considered failed if it cannot start within the specified time period or runs longer than the specified time period. To specify the timeouts period, you should use the timeOutInMinutes
keyword inside timeOut
. The default and maximum allowed timeout is 120 minutes.
timeOut(init: TimeOutFailedCondition.() -> Unit)
|
For example:
job.volumeSize
volumeSize
sets the size of the disk mounted to a container. The disk contains project repository. By default, 5 GiBs. Supports the mb
and gb
units for MB and GB. For example, 10000.mb
or 10.gb
.
volumeSize: Any?
For example:
job.kaniko
kaniko
is a special step used to build and publish Docker images. The step runs in a container based on a custom image with the Kaniko tool. Learn more
kaniko(init: KanikoStep.() -> Unit)
|
For example:
job.gradlew
gradlew
is a special helper item that runs Gradle commands using Gradle wrapper from the project directory. Use gradlew
to simplify your build scripts. Learn more
gradlew(image: String? = null, vararg args: String, init: Project.Container.() -> Unit = {})
| |
| |
|
For example:
job.warmup (Deprecated)
warmup
lets you prepare warm-up data for dev environments.
warmup(ide: Ide, profileId: String? = null, init: Warmup.() -> Unit = {})
| |||||||||
| |||||||||
|
For example:
job.warmup.env
env
lets you set environment variables in a dev environment container. Note that you can get various information about the current run context with the help of Automation environment variables.
env = Environment()
The
|
For example: