Skip to content

GitLab CI Kotlin DSLopensavvy.gitlab.ciJobcache

cache

fun cache(configuration: Cache.() -> Unit)

Declares paths that will be reused between different jobs, even if they are of different pipelines.

Note that this is very easy to misuse in ways that make the pipeline less reliable or slower. In particular, avoid caching node_modules or ~/.gradle or other dependency download caches if you're using GitLab Shared Runners, as downloading the cached dependencies can easily become slower than downloading the dependencies themselves.

Instead, use systems like Gradle's remote build cache, GitLab's dependency proxy.

To learn more about configuring the cache, see Cache.

Example

val test by job {
    cache {
        include(".gradle/wrapper")
        keyFile("gradle/wrapper/gradle-wrapper.properties")
    }

    script {
        echo("./gradlew test")
    }
}

This particular example is inspired by the Gradle plugin, which we recommend instead of implementing this manually.

External resources