I have a Jenkins pipeline, for a PHP project in a Docker container. This is my Jenkinsfile:
pipeline {
agent any
stages {
stage('Build') {
agent any
steps {
sh 'docker-compose up -d'
sh 'docker exec symfony composer install'
}
}
stage('Test') {
steps {
sh 'docker exec symfony php ./bin/phpunit --coverage-clover=\'reports/coverage/coverage.xml\' --coverage-html=\'reports/coverage\' --coverage-crap4j=\'reports/crap4j.xml\''
}
}
stage('Coverage') {
steps {
step([$class: 'CloverPublisher', cloverReportDir: '/reports/coverage', cloverReportFileName: 'coverage.xml'])
}
}
}
post {
cleanup {
sh 'docker-compose down -v'
cleanWs()
}
}
}
After running the pipeline, the var/lib/jenkins/workspace
folder contains 4 folders (assuming my project name is Foo
):
What are these, and how do I clean them up? cleanWs
does not remove any except the first of them after the build.
EDIT: This is not a duplicate of this question because
deleteDir
, which is not recommended when using Docker containers. There is an opened Jenkins issue about deleteDir() not deleting the @tmp/@script/@... directories.
A workaround to delete those:
post {
always {
cleanWs()
dir("${env.WORKSPACE}@tmp") {
deleteDir()
}
dir("${env.WORKSPACE}@script") {
deleteDir()
}
dir("${env.WORKSPACE}@script@tmp") {
deleteDir()
}
}
}
There is also a comment on the issue describing what @tmp is:
It [@tmp folder] contains the content of any library that was loaded at run time. Without a copy, Replay can't work reliably.
The Foo@2 Foo@2@tmp folders were created because the agent was defined 2 times. Once it was defined at the top level inside the pipeline block. And once inside the stage called build. The working folder of stage 'build' is the Foo@2 folder.
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