问题描述
我有一个Jenkins管道,用于Docker容器中的PHP项目。这是我的Jenkinsfile:
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()
}
}
}
在运行管道之后, var / lib / jenkins / workspace
文件夹包含4个文件夹( umum我的项目名称是 Foo
):
After running the pipeline, the var/lib/jenkins/workspace
folder contains 4 folders (assuming my project name is Foo
):
- Foo
- Foo @ 2
- Foo @ 2 @ tmp
- Foo @ tmp
- Foo
- Foo@2
- Foo@2@tmp
- Foo@tmp
这些是什么,我该如何清理它们? cleanWs
不会删除除构建后的第一个以外的任何东西。
What are these, and how do I clean them up? cleanWs
does not remove any except the first of them after the build.
编辑:这不是对,因为
- 该问题不能回答我的问题:这些文件是什么。
- 该问题的答案建议使用
deleteDir
,当使用Docker容器时,。
- That question does not answer my question: what are these files.
- The answers to that question suggest using
deleteDir
, which is not recommended when using Docker containers.
推荐答案
有一个打开的,关于deleteDir()不删除@ tmp / @ script / @ ...目录。
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()
}
}
}
还有一个关于描述 @tmp 是什么的问题:
There is also a comment on the issue describing what @tmp is:
这篇关于Jenkins工作区中的@tmp文件夹是什么以及如何清理它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!