Package-level declarations
Jobs, stages, dependencies and more: declaring a GitLab CI pipeline from Kotlin.
Most of the objects are identical, or very similar, to their equivalent in the Yaml format. Some have been renamed or restructured for readability.
Overview
A pipeline is created by the gitlabCi function. It can be converted to Yaml by calling its println function:
gitlabCi {
// Declare your pipeline here
}.println()
A pipeline is composed of stages, themselves composed of jobs. Each job is a unit of work, which will be executed independently by GitLab. A job can do anything that you can write a program for. Most commonly, jobs use Docker images to provide a ready-to-use environment.
gitlabCi {
// Create two stages: test and deploy
val test by stage()
val deploy by stage()
// First job to test our app
val build by job(stage = test) {
image("ubuntu")
script {
shell("make")
}
artifacts {
// The 'build' directory will be stored when the job is over
include("build")
}
}
if (Value.isDefaultBranch) {
val publish by job(stage = deploy) {
image("ubuntu")
// Wait for 'build' to finish before starting,
// and download the artifacts it generated
dependsOn(build, artifacts = true)
script {
// Add your own logic
}
}
}
}.println()
Reading order
Types
Entrypoint to the GitLab CI pipeline generation.
Marker for APIs that are part of the GitLab CI DSL.
A single execution step in a pipeline.
Configuration for job retry behavior.
Failure types that can be used with Retry.on.
Objects that can be converted to Yaml.