Jenkins pipeline - Remove @tmp folder

我是研究僧i 提交于 2020-02-22 08:10:26

问题


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:

  • https://issues.jenkins-ci.org/browse/JENKINS-44909
  • https://issues.jenkins-ci.org/browse/JENKINS-41805

回答1:


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.




回答2:


You can use deleteDir() as the last step of the pipeline Jenkinsfile (assuming you didn't change the working directory).




回答3:


The following code snippet works great.

//@tmp clean up
stage ('cleanup') 
{
  withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']) {
  dir('<your directory path>') {
  sh "rm -rf <directory `enter code here`name>@tmp"
  }
  }
}


来源:https://stackoverflow.com/questions/55297411/jenkins-pipeline-remove-tmp-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!