1. 使用cleanWs
stage('Clean') { steps { cleanWs( cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, cleanupMatrixParent: true, disableDeferredWipeout: true, # 这个选项是关闭延时删除,立即删除。 deleteDirs: true ) } }
2. 使用 deleteDir
dir('directoryToDelete') { deleteDir() }
参考链接:https://www.thinbug.com/q/37468455