I am using "Workspace Cleanup Plugin" to clean workspace after the job finishes. But still @tmp directory is not deleted.
Any way we can delete this @tmp folder using pipeline script.
It looks like a known issue as far as I see in Jira:
I am using "Workspace Cleanup Plugin" to clean workspace after the job finishes. But still @tmp directory is not deleted.
Any way we can delete this @tmp folder using pipeline script.
It looks like a known issue as far as I see in Jira:
I used custom workspace in Jenkins then deleteDir() will not delete @tmp folder.
So to delete @tmp along with workspace use following
pipeline {
agent {
node {
customWorkspace "/home/jenkins/jenkins_workspace/${JOB_NAME}_${BUILD_NUMBER}"
}
}
post {
cleanup {
/* clean up our workspace */
deleteDir()
/* clean up tmp directory */
dir("${workspace}@tmp") {
deleteDir()
}
/* clean up script directory */
dir("${workspace}@script") {
deleteDir()
}
}
}
}
This snippet will work for default workspace also.
Not a direct answer to your question, but might help someone.
If you are using the dir Jenkins pipeline step to change directories, then you'll see these @tmp folders getting created. Instead, use the cd command and they won't get created in the first place.
So, instead of,
def myFunc(String folder) {
dir(folder) {
// work
}
}
Do this.
def myFunc(String folder) {
bat "cd ${folder}"
// work
}