Docker
The Docker library will build docker images and push them into a docker repository.
Steps Contributed
Step | Description |
---|---|
|
builds a container image, tagging it with the Git SHA, and pushes the image to the defined registry |
|
inspects the source code repository based upon the configured |
|
logs in to the configured container registry |
|
retags the container images determined by |
Example Configuration Snippet
libraries{
docker {
build_strategy = "dockerfile"
registry = "docker-registry.default.svc:5000"
cred = "openshift-docker-registry"
repo_path_prefix = "proj-images"
remove_local_image = true
build_args{
GITHUB_TOKEN{
type = "credential"
id = "github_token"
}
SOME_VALUE = "some-inline-value-here"
}
}
}
Configurations
Field | Description | Default Value | Required |
---|---|---|---|
build_strategy |
Sets how the library will build the container image(s); Must be dockerfile, docker-compose, or modules |
dockerfile |
false |
registry |
Where the container images produced during the pipeline builds are going to be pushed to |
true |
|
cred |
Credentials used for the repository where different docker pipeline tools are stored. |
true |
|
repo_path_prefix |
The part of the repository name between the registry name and the last forward-slash |
"" |
false |
remove_local_image |
Determines if the pipeline should remove the local image after building or retagging |
false |
false |
Build Arguments
Static Inline Build Arguments
To pass static values as build arguments, set a field within the configuration block where the key is the build argument name and the value is the build argument value.
For example,
libraries{
docker{
build_args{
BUILD_ARG_NAME = "some-inline-argument" (1)
}
}
}
1 | This configuration would result in --build-arg BUILD_ARG_NAME='some-inline-argument' being passed to docker build |
Secret Text Credentials
To pass a secret value, ensure that a Secret Text credential type has been created and fetch the credential id from the Jenkins credential store.
libraries{
docker{
build_args{
GITHUB_TOKEN{ (1)
type = "credential" (2)
id = "theCredentialId" (3)
}
}
}
}
1 | This will result in the build argument --build-arg GITHUB_TOKEN=<secret text> being passed to docker build . The library will mask the value of the secret from the build log. |
2 | The type of "credential" must be set. This gives the library flexibilty in the future to support other build argument types |
3 | This credential must exist and be a Secret Text credential in the Jenkins credential store. The library could be extended in the future to support other types of credentials, when necessary. |