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

Start with gitlabCi, stages and jobs.

Types

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
data class Depends(val job: Job, val artifacts: Boolean, val optional: Boolean) : YamlExport
Link copied to clipboard

Entrypoint to the GitLab CI pipeline generation.

Link copied to clipboard
annotation class GitLabCiDsl

Marker for APIs that are part of the GitLab CI DSL.

Link copied to clipboard
class Job : YamlExport

A single execution step in a pipeline.

Link copied to clipboard

Configuration for job retry behavior.

Link copied to clipboard

Failure types that can be used with Retry.on.

Link copied to clipboard
data class Stage(val name: String)

A stage in a pipeline.

Link copied to clipboard
object Value
Link copied to clipboard
object Variable

Predefined variables in GitLab CI.

Link copied to clipboard
Link copied to clipboard
interface YamlExport

Objects that can be converted to Yaml.

Functions

Link copied to clipboard
fun gitlabCi(block: GitLabCi.() -> Unit): <Error class: unknown class>

Convenience factory function for GitLabCi.

Link copied to clipboard
fun GitLabCi.job(name: String, stage: Stage? = null, block: Job.() -> Unit): <Error class: unknown class>
fun GitLabCi.job(name: String? = null, stage: Stage? = null, block: Job.() -> Unit = {}): <Error class: unknown class>

Declares a new Job in the current pipeline.

Link copied to clipboard

Creates a stage with a given name.

Creates a stage automatically named after the variable it is assigned to.