I have a step in my Jenkinsfile that runs using a Dockerfile
agent. When jenkins creates the docker image it gives it a random long tag and I'd like to replace that with my own tag. I tried passing the tag using additionalBuildArgs
but that gives the docker image an additional tag.
agent {
dockerfile {
additionalBuildArgs '-t my-image:latest'
}
}
Is there a way to stop Jenkins from passing a tag?
Pipeline is designed to easily use Docker images as the execution environment for a single Stage or the entire Pipeline. Meaning that a user can define the tools required for their Pipeline, without having to manually configure agents. Practically any tool which can be packaged in a Docker container.
Manage Jenkins → Manage Plugins In Jenkins you have to add a new credential with your Docker Hub account details. Go to Credentials → Global → Add credentials and fill out the form with your username and password. Create your Jenkins pipeline.
The plugin that controls this action is pipeline-model-definition-plugin.
you can see at the plugin's code that the image name is a hash of the project name and the dockerfile path:
def hash = Utils.stringToSHA1("${runWrapper.fullProjectName}\n${script.readFile("${dockerfilePath}")}")
def imgName = "${hash}"
then it takes the additional args and adds them to the image name:
def additionalBuildArgs = describable.getAdditionalBuildArgs() ? " ${describable.additionalBuildArgs}" : ""
script.sh "docker build -t ${imgName}${additionalBuildArgs} -f \"${dockerfilePath}\" \"${describable.getActualDir()}\""
so by using the dockerfile step, it seems that the name would always be a hash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With