Search code examples
dockerjenkins-pipeline

tagging docker image in Jenkinsfile


after build a docker image using docker.build(<image_name_1>) I want to tag the docker image_name_1 to image_name_2 using jenkinsfile. Is there a way to do it using docker.tag? or I should use sh?


Solution

  • Yes, you can use the docker.tag global var method for this:

    // store the resulting build object in the variable "image"
    image = docker.build(<image_name_1>)
    // re-tag the image
    image.tag(image_name_2)
    

    and then your image will have both tags locally, and both tags can also be pushed to a registry.