Methods to handle Docker registry actions.
def dockerRegistry = new Registry(this)
// init docker registry
dockerRegistry.init(
usernamePasswordCredential : 'my-docker-registry-credential',
url : 'https://registry.docker-image.com/',
)
This class rely on the version defined in Dockefile. Based on Dockerfile reference, the proper way to define version for a Dockefile is:
LABEL version="1.0.0"
Please note, we only support semantic versioning and the version label line cannot be combined with other label key=value pairs.
| Modifiers | Name | Description |
|---|---|---|
static java.lang.String |
DEFAULT_DOCKERFILE |
Constant of default Dockerfile file path and name |
static java.lang.String |
DEFAULT_IMAGE_TAG |
Default Docker image tag. |
| Type | Name and description |
|---|---|
java.lang.String |
_imageTemporary image name |
java.lang.String |
_urlDocker registry without https:// or http:// |
java.lang.String |
buildArgsExtra build args supplied through pipeline |
java.lang.String |
dockerFileFile path and name of Dockerfile. |
java.lang.String |
imageDocker image name |
java.lang.Object |
stepsReference to the groovy pipeline variable. |
java.lang.String[] |
tagsDocker image tags, can be multiple |
java.lang.String |
urlDocker registry url |
java.lang.String |
usernamePasswordCredentialJenkins credential ID for Docker registry username/password(token) |
java.lang.String |
versionImage version extracted from Dockerfile |
| Constructor and description |
|---|
Registry
(java.lang.Object steps)Constructs the class. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
java.lang.String |
build(java.util.Map args = [:])Build docker image. |
|
java.lang.String |
build(java.lang.String dockerFile)Build docker image. |
|
void |
clean()Remove last build image |
|
java.lang.String |
getFullImageName(java.lang.String tag)Return full image name |
|
java.lang.String |
getImageId()Return the image ID from last build |
|
void |
init(java.util.Map args = [:])Initialize Docker registry properties. |
|
void |
publish(java.util.Map args = [:])Publish the image to registry. |
|
void |
publish(java.lang.String image, java.lang.String tags = '')Publish the image to registry. |
|
void |
publish(java.lang.String image, java.lang.String[] tags)Publish the image to registry. |
|
java.lang.String |
tag(java.lang.String tag)Tag the build image |
|
void |
version(java.util.Map args = [:])Declare a new version of Docker image. |
|
void |
version(org.zowe.jenkins_shared_library.scm.GitHub github, java.lang.String branch, java.lang.String version = 'PATCH')Declare a new version of docker image. |
|
void |
within(java.util.Map args, groovy.lang.Closure body)Execute scripts within proper docker registry authentication |
|
void |
within(groovy.lang.Closure body)Execute scripts within proper docker registry |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Constant of default Dockerfile file path and name
"Dockerfile"Default Docker image tag.
"latest"Temporary image name
Docker registry without https:// or http://
''Extra build args supplied through pipeline
File path and name of Dockerfile.
Docker image name
Reference to the groovy pipeline variable.
Docker image tags, can be multiple
Docker registry url
''Jenkins credential ID for Docker registry username/password(token)
Image version extracted from Dockerfile
Constructs the class.
When invoking from a Jenkins pipeline script, the Pipeline must be passed the current environment of the Jenkinsfile to have access to the steps.
def dockerRegistry = new Registry(this)
steps - The workflow steps object provided by the Jenkins pipelineBuild docker image.
// build docker image from ./my-sub-folder/Dockerfile
// it returns image ID (hash)
def imageId = dockerRegistry.build(
dockerFile : './my-sub-folder/Dockerfile'
)
Build docker image.
Remove last build image
Return full image name
tag - docker image tag nameReturn the image ID from last build
Initialize Docker registry properties.
args Map.url - the registry URLusernamePasswordCredential - Jenkins credential ID for Docker registry username/password(token). Optional.dockerFile - Dockerfile file path and name. Optional, default is DEFAULT_DOCKERFILE.image - docker image nametag - docker image tagtags - docker image tags, can be multiplePublish the image to registry.
// publish last build image to registry
// the image will also be tagged as latest, v1.x and v1.2.3
dockerRegistry.publish(
image : 'my-user/my-image',
tags : ['latest', 'v1.x', 'v1.2.3'],
)
Publish the image to registry.
Publish the image to registry.
Tag the build image
tag - tag nameDeclare a new version of Docker image.
def github = new org.zowe.jenkins_shared_library.scm.GitHub(this)
// bump patch version on master branch
dockerRegistry.version(
github : github,
branch : 'master',
version : 'patch'
)
// After this, you should be able to see your repository master branch has a commit of
// version bump.
github - GitHub instance must have been initialized with repository, credential, etcbranch - which branch to releaseversion - what kind of version bump we should makeDeclare a new version of docker image.
Execute scripts within proper docker registry authentication
body - a CLosure scripts to run within the registrryExecute scripts within proper docker registry
Groovy Documentation