Skip to content

GitLab CI Kotlin DSLopensavvy.gitlab.ci.pluginsDockerbuild

build

fun build(image: String, version: String = defaultVersion, dockerfile: String = "Dockerfile", context: String = ".", previousVersions: List<String> = listOf("latest")): 

Builds a Docker image from a Dockerfile.

The image will be built but not published anywhere, remember to call push after building it.

The images built by this function have the BuildKit Inline Cache enabled, and can therefore be used as caching for future builds.

Parameters

image

The name of the image that will be built (e.g. "backend").

version

The version which will be assigned to the built image. By default, the version number is created from the pipeline identifier, to ensure two pipelines do not overwrite each other.

dockerfile

The path to the Dockerfile, relative to the current working directory.

context

The path of the directory in which the build takes place, relative to the current working directory. The files in this directory will be available in the Dockerfile's COPY instruction.

previousVersions

Version names of previous versions that are candidate for caching. If Docker finds identical layers in these images from what is currently being built, it will reuse the existing layers, greatly speeding the build. Note that for Docker to use an image as a cache layer, it must have caching enabled.

Samples

opensavvy.gitlab.ci.plugins.DockerTest.buildImage