Jenkins 詹金斯管道公司“;无法删除";使用deleteDir

Jenkins 詹金斯管道公司“;无法删除";使用deleteDir,jenkins,jenkins-pipeline,Jenkins,Jenkins Pipeline,我有一个jenkins管道,末尾有一个post调用。看起来像这样: post { always { deleteDir() } } 这是日志: [Pipeline] { (Declarative: Post Actions) [Pipeline] deleteDir Error when executing always post condition: java.io.IOException: Unable to delete '/var/jenkins_hom

我有一个jenkins管道,末尾有一个
post
调用。看起来像这样:

post {
    always {
        deleteDir()
    }
}
这是日志:

[Pipeline] { (Declarative: Post Actions)
[Pipeline] deleteDir
Error when executing always post condition:
java.io.IOException: Unable to delete '/var/jenkins_home/workspace/abide/.git/logs/refs/heads/master'. Tried 3 times (of a maximum of 3) waiting 0.1 sec between attempts.
    at hudson.Util.deleteFile(Util.java:277)
    at hudson.FilePath.deleteRecursive(FilePath.java:1322)
    at hudson.FilePath.deleteContentsRecursive(FilePath.java:1331)
    at hudson.FilePath.deleteRecursive(FilePath.java:1313)
    at hudson.FilePath.deleteContentsRecursive(FilePath.java:1331)
    at hudson.FilePath.deleteRecursive(FilePath.java:1313)
    at hudson.FilePath.deleteContentsRecursive(FilePath.java:1331)
    at hudson.FilePath.deleteRecursive(FilePath.java:1313)
    at hudson.FilePath.deleteContentsRecursive(FilePath.java:1331)
    at hudson.FilePath.deleteRecursive(FilePath.java:1313)
    at hudson.FilePath.deleteContentsRecursive(FilePath.java:1331)
    at hudson.FilePath.deleteRecursive(FilePath.java:1313)
    at hudson.FilePath.access$1600(FilePath.java:209)
    at hudson.FilePath$DeleteRecursive.invoke(FilePath.java:1291)
    at hudson.FilePath$DeleteRecursive.invoke(FilePath.java:1287)
    at hudson.FilePath.act(FilePath.java:1095)
    at hudson.FilePath.act(FilePath.java:1078)
    at hudson.FilePath.deleteRecursive(FilePath.java:1285)
    at org.jenkinsci.plugins.workflow.steps.DeleteDirStep$Execution.run(DeleteDirStep.java:77)
    at org.jenkinsci.plugins.workflow.steps.DeleteDirStep$Execution.run(DeleteDirStep.java:69)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49)
    at hudson.security.ACL.impersonate(ACL.java:290)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.nio.file.FileSystemException: /var/jenkins_home/workspace/abide/.git/logs/refs/heads/master: Operation not permitted
    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
    at sun.nio.fs.UnixFileAttributeViews$Posix.setMode(UnixFileAttributeViews.java:238)
    at sun.nio.fs.UnixFileAttributeViews$Posix.setPermissions(UnixFileAttributeViews.java:260)
    at java.nio.file.Files.setPosixFilePermissions(Files.java:2045)
    at hudson.Util.makeWritable(Util.java:337)
    at hudson.Util.tryOnceDeleteFile(Util.java:297)
    at hudson.Util.deleteFile(Util.java:272)
    ... 27 more

[Pipeline] }
[Pipeline] // stage
[Pipeline] }

通常情况下,删除失败是由于权限或文件被锁定。尝试在DeleteDir之前在脚本中放置一个sleep,看看是否可以在脚本暂停时在另一个窗口中删除该目录。确保睡眠时间足够长,让你有时间四处走动。如果您在windows上,SysInternals的Process Explorer之类的工具可以帮助您找到保存文件的进程。它是免费的,易于安装,易于使用-只需按查找并粘贴您试图删除的文件名。