Skip to content

GitLab CI Kotlin DSL

Generate your GitLab CI pipeline with Kotlin.

Configuration

First, install Kotlin. You can do so using your package manager of choice. Create a gitlab-ci.main.kts file with the following content:

#!/usr/bin/env kotlin

@file:DependsOn("dev.opensavvy.gitlab:gitlab-ci-kotlin-jvm:VERSION-HERE") // See https://gitlab.com/opensavvy/automation/gitlab-ci.kt/-/releases

import opensavvy.gitlab.ci.*
import opensavvy.gitlab.ci.script.*

val pipeline = gitlabCi {
    val test by stage()

    val helloWorld by job(stage = test) {
        script {
            shell("echo 'Hello world'")
        }
    }
}

pipeline.println()

Allow execution for this file (on UNIX machines: chmod u+x gitlab-ci.main.kts), then execute it (on UNIX machines: ./gitlab-ci.main.kts). Congratulation, you have just written your first GitLab CI pipeline in Kotlin!

Packages

opensavvy.gitlab.ci

Jobs, stages, dependencies and more: declaring a GitLab CI pipeline from Kotlin.

opensavvy.gitlab.ci.plugins

Easily use Gradle, Helm, Docker and more within your pipelines.

opensavvy.gitlab.ci.script

Methods related to declaring the script part of jobs.

opensavvy.gitlab.ci.utils

Helpers to make the syntax nicer.

opensavvy.gitlab.ci.yaml

Lightweight embedded implementation of a Yaml serializer.