Skip to content

GitLabCi

Entrypoint to the GitLab CI pipeline generation.

A pipeline is split into multiple stages, each split into multiple jobs.

To create a pipeline, use the factory function:

val pipeline = gitlabCi {
    // Declare the different stages
    // Declare the different jobs
}

Once the pipeline is configured as you'd like, call toYaml or println to build the configuration file.

Constructors

GitLabCi

constructor()

Functions

job

fun GitLabCi.job(
    name: String, 
    stage: Stage? = null, 
    block: Job.() -> Unit
): Job

Declares a new Job in the current pipeline.

A job is a unit of work in a pipeline: each job is executed by a runner. Jobs can have dependencies, artifacts and more.

Example
gitlabCi {
    val build by job {
        useGradle()

        script {
            gradlew.task("build")
        }
    }
}.println()
External documentation

Parameters

  • name: The name of the job. See Job.name. If using the by syntax, the default name is the name of the variable the job is assigned to.

  • stage: The stage this job is part of. If unset, see the official documentation.

fun GitLabCi.job(
    name: String? = null, 
    stage: Stage? = null, 
    block: Job.() -> Unit = {}
): DelegateProvider<GitLabCi, ReadOnlyDelegate<Job>>

Declares a new Job in the current pipeline.

A job is a unit of work in a pipeline: each job is executed by a runner. Jobs can have dependencies, artifacts and more.

Example
gitlabCi {
    val build by job {
        useGradle()

        script {
            gradlew.task("build")
        }
    }
}.println()
External documentation

Parameters

  • name: The name of the job. See Job.name. If using the by syntax, the default name is the name of the variable the job is assigned to.

  • stage: The stage this job is part of. See Job.stage.

kanikoBuild

fun GitLabCi.kanikoBuild(
    imageName: String, 
    imageVersion: String = defaultVersion, 
    context: String = ".", 
    dockerfile: String = "/Dockerfile", 
    jobName: String? = null, 
    stage: Stage? = null, 
    block: Job.() -> Unit = {}
): DelegateProvider<GitLabCi, ReadOnlyDelegate<Job>>

Creates a job that builds the image imageName with version imageVersion. If the imageName contains a registry name, pushes the image to the registry.

kanikoRename

fun GitLabCi.kanikoRename(
    imageName: String, 
    oldVersion: String = defaultVersion, 
    newVersion: String = "latest", 
    jobName: String? = null, 
    stage: Stage? = null, 
    block: Job.() -> Unit = {}
): DelegateProvider<GitLabCi, ReadOnlyDelegate<Job>>

Creates a job that changes the version of the image imageName from oldVersion to newVersion.

println

fun println()

Generates the Yaml of this pipeline, and prints it to the standard output.

stage

fun GitLabCi.stage(name: String): Stage

Creates a stage with a given name.

Example:

val pipeline = gitlabCi {
    val build = stage("some-other-name")
}

To automatically generate the name from the variable, see stage.

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

Example:

val pipeline = gitlabCi {
    val build by stage()
}

To use a different name than the variable's name, use the stage function.

toYaml

open override fun toYaml(): Yaml.Collection.MapLiteral

Converts this object into a Yaml object.