I’m running Jenkins in a docker container, and each agent is it’s own docker container specified by their own Dockerfiles. The problem is that this eats up all my disk space because jenkins tags each docker image with some hash, ie.
docker build -t c83bea504ba5821d16993281b93536740e567b55 -f Dockerfile .
I tried specifying my own tag with additionalBuildArgs
but that just appends another tag and two images get created
docker build -t c83bea504ba5821d16993281b93536740e567b55 -t project-test:latest -f Dockerfile .
$ sudo docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
c83bea504ba5821d16993281b93536740e567b55 latest b46746417e26 3 minutes ago 568MB
project-test latest b46746417e26 3 minutes ago 568MB
jenkins-jenkins
How can I specify my own tag for the docker images? Examples from the docker plugin documentation seem to use a scripted pipeline to customize more aspects of docker images but that makes other things like workspace cleanup more complicated.
Jenkinsfile:
pipeline {
agent {
dockerfile {
additionalBuildArgs '-t project-test:latest'
args '''
--group-add=46
--group-add=20
...
'''
}
}
stages {
stage('Build') {
steps {
sh '''#!/bin/bash
echo dummy build command
'''
}
}
stage('Test') {
steps {
sh 'echo dummy test command'
}
}
}
post {
always {
cleanWs(cleanWhenNotBuilt: false,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true)
}
}
}