Adding tags to docker image from jenkins

后端 未结 3 1796

I have a jenkins instance (which actually runs inside docker) for my Continous Integration.

The jenkins server builds docker images on an external docker host, tests

相关标签:
3条回答
  • 2020-12-20 18:09

    As shown in this blog post you can add two tags with the push command like so:

    stage('Push image') {
        docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') {
            app.push("${env.BUILD_NUMBER}")
            app.push("latest")
        }
    }
    

    PS Mind you Jenkins folks if you're reading this a 3rd party blog post does NOT count as documentation. This could have been resolved MUCH quicker had this been properly documented.

    0 讨论(0)
  • 2020-12-20 18:12

    As you do not link to any of the plugins you use I cannot easily say if they might be able to re-tag an existing image, it is however possible via a shell based job.

    If you use a shell (bash or something similar) script in Jenkins you can easily do this with a standard docker command for tagging existing images. If your my-app:test image is already cached locally for your jenkins build job you can run:

    docker login -u $USER -p $PASSWORD <myregistry.example.org>
    docker pull my-app:tested 
    docker tag my-app:tested my-app:vX.X
    docker push my-app:vX.X
    

    If my-app:tested is cached locally for the jenkins job you can omit the docker pull command. See the docker tag documentation for more information. If this shell commands-based workflow does not fit into your plugins-based build workflow I'm not sure how you would do it.

    I do not personally use Jenkins or Jenkins plugins for building docker images, so I am not familiar with how plugins for building Docker images work in Jenkins. Someone else might be able to help you with a plugin based build job.

    0 讨论(0)
  • 2020-12-20 18:12

    I'd add the below to other answers:

    app.tag(["tag1","latest"])
    

    Image.tag([tagname])

    Runs docker tag to record a tag of this image (defaulting to the tag it already has). Will rewrite an existing tag if one exists.

    From Jenkins docker step docs, at https://your/jenkins/instance/URL/pipeline-syntax/globals#docker

    0 讨论(0)
提交回复
热议问题