Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding tags to docker image from jenkins

Tags:

docker

jenkins

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 them and then pushes them to tagged with my-app:tested.

Now, when I build a release, I want to re-tag the docker image from tested to vX.X. I do not want rebuild the image with a new tag, I want to re-tag the existing image.

How can this be done with jenkins? I am looking through the jenkins plugins and cannot find any with this capability.

like image 348
Nathan Avatar asked Sep 19 '16 09:09

Nathan


People also ask

How do I add tags while building Docker image?

docker build -t image_name:tag_name . otherwise it will give latest tag to you image automatically. Save this answer.

How do I tag an image in Docker?

Docker tags are just an alias for an image ID. The tag's name must be an ASCII character string and may include lowercase and uppercase letters, digits, underscores, periods, and dashes. In addition, the tag names must not begin with a period or a dash, and they can only contain 128 characters.

Can we run Docker image from Jenkins?

Docker's fundamental platform and container design means that a single Docker image (for any given application like Jenkins) can be run on any supported operating system (macOS, Linux and Windows) or cloud service (AWS and Azure) which is also running Docker.

How do I push multiple tags in Docker?

Use the -a (or --all-tags ) option to push all tags of a local image. The following example creates multiple tags for an image, and pushes all those tags to Docker Hub.


1 Answers

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.

like image 155
meh Avatar answered Sep 22 '22 09:09

meh