catbot
catbot

Reputation: 2049

How to tag Docker images with a Git tag in Jenkins?

Hopefully I'm just missing something simple, but I cannot figure out how to tag a Docker image with a Git tag in a Jenkins job.

I have been using the Docker Build and Publish plugin for building my images, but it's tag input only seems to accept token macros for input. The Git plugin doesn't export a tag macro and I haven't been able to find an alternative plugin that does. I had tried exporting the results of git-describe with the Envinject plugin into the environment but the Docker plugin doesn't seem to be able to read environment variables, even with the ${ENV,var=VARIABLE} token macro.

I can achieve this by scripting the whole process, but I was hoping to use the Docker plugin for registry credentials management.

Upvotes: 5

Views: 4057

Answers (1)

catbot
catbot

Reputation: 2049

After taking another look at the problem with a clearer head, I found a simple solution to this problem in scripting the creation a temporary properties file with my git tag and using Envinject's "Inject environment variables" build step to read that file.

My final configuration looked somewhat like this: enter image description here

Upvotes: 6

Related Questions