我们有一台Jenkins服务器已经成功构建了200多次代码 - 直到几天前。
我们现在收到一个错误,表明Jenkins无法删除工作区(完整的消息跟随标识元素被编辑。)
我已经查看了最近的代码更改,并且看不到任何可能导致此问题的内容,并且该服务器上的任何内容都没有更改数周。
堆栈跟踪表明"上下文类hudson.FilePath缺失",但配置尚未从配置中更改超过200次。
有人可以提出可以解决这个问题的步骤吗?
Started by user <REDACTED>
> git rev-parse --is-inside-work-tree # timeout=10
Setting origin to https://<REDACTED>@bitbucket.org/<REDACTED>/<REDACTED>.git
> git config remote.origin.url
https://<REDACTED>@bitbucket.org/<REDACTED>/<REDACTED>.git # timeout=10
Fetching origin...
Fetching upstream changes from origin
> git --version # timeout=10
using GIT_ASKPASS to set credentials <REDACTED>@bitbucket
> git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/*
Seen branch in repository origin/master
Seen branch in repository origin/temp
Seen 2 remote branches
Obtained code/Jenkinsfile from <REDACTED>
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/<REDACTED>
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
Cloning repository https://<REDACTED>@bitbucket.org/<REDACTED>/<REDACTED>.git
ERROR: Failed to clean the workspace
java.io.IOException: Unable to delete '/var/lib/jenkins/workspace/<REDACTED>. Tried 3 times (of a maximum of 3) waiting 0.1 sec between attempts.
at hudson.Util.deleteContentsRecursive(Util.java:252)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:555)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1120)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1160)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:113)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:85)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:75)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
at hudson.security.ACL.impersonate(ACL.java:290)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
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/lib/jenkins/workspace/<REDACTED>/code/<REDACTED>-query/target/classes/application.properties: 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:332)
at hudson.Util.tryOnceDeleteFile(Util.java:292)
at hudson.Util.tryOnceDeleteRecursive(Util.java:383)
at hudson.Util.tryOnceDeleteContentsRecursive(Util.java:402)
at hudson.Util.tryOnceDeleteRecursive(Util.java:382)
at hudson.Util.tryOnceDeleteContentsRecursive(Util.java:402)
at hudson.Util.tryOnceDeleteRecursive(Util.java:382)
at hudson.Util.tryOnceDeleteContentsRecursive(Util.java:402)
at hudson.Util.tryOnceDeleteRecursive(Util.java:382)
at hudson.Util.tryOnceDeleteContentsRecursive(Util.java:402)
at hudson.Util.tryOnceDeleteRecursive(Util.java:382)
at hudson.Util.tryOnceDeleteContentsRecursive(Util.java:402)
at hudson.Util.deleteContentsRecursive(Util.java:247)
... 14 more
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Failed to delete workspace
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:558)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1120)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1160)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:113)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:85)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:75)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
at hudson.security.ACL.impersonate(ACL.java:290)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
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.io.IOException: Unable to delete '/var/lib/jenkins/workspace/<REDACTED>'. Tried 3 times (of a maximum of 3) waiting 0.1 sec between attempts.
at hudson.Util.deleteContentsRecursive(Util.java:252)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:555)
... 13 more
Caused by: java.nio.file.FileSystemException: /var/lib/jenkins/workspace/<REDACTED>/code/<REDACTED>-query/target/classes/application.properties: 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:332)
at hudson.Util.tryOnceDeleteFile(Util.java:292)
at hudson.Util.tryOnceDeleteRecursive(Util.java:383)
at hudson.Util.tryOnceDeleteContentsRecursive(Util.java:402)
at hudson.Util.tryOnceDeleteRecursive(Util.java:382)
at hudson.Util.tryOnceDeleteContentsRecursive(Util.java:402)
at hudson.Util.tryOnceDeleteRecursive(Util.java:382)
at hudson.Util.tryOnceDeleteContentsRecursive(Util.java:402)
at hudson.Util.tryOnceDeleteRecursive(Util.java:382)
at hudson.Util.tryOnceDeleteContentsRecursive(Util.java:402)
at hudson.Util.tryOnceDeleteRecursive(Util.java:382)
at hudson.Util.tryOnceDeleteContentsRecursive(Util.java:402)
at hudson.Util.deleteContentsRecursive(Util.java:247)
... 14 more
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] step
Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
ERROR: Error cloning remote repo 'origin'
Finished: FAILURE
答案 0 :(得分:20)
我终于找到了说明所有问题的解决方案。
原因:
我在Jenkins中使用docker,并在Docker(-v pwd:/code:rw
)中挂载了Jenkins工作目录。
在运行时,我的程序生成了几个文件,这些文件在挂载时也会进入Jenkins工作目录。但是该用户是docker根用户,而不是Jenkins用户,因为该Jenkins用户无法删除这些文件并导致此错误。
解决方案: 您还可以与docker共享Jenkins用户,因此创建的所有文件都与Jenkins本身创建的文件相同。
docker run --user "$(id -u):$(id -g)" -i --rm -v /etc/passwd:/etc/passwd:ro -v `pwd`:/code:rw docker_image:tag
因此添加可以通过在Docker内部使用Jenkins用户基本上解决此问题。
--user "$(id -u):$(id -g)" -v /etc/passwd:/etc/passwd:ro
答案 1 :(得分:8)
工作区中存在锁定文件或目录的内容。
其他一些类似的案例。
如果您拥有对FS的shell访问权限,请使用&#39; lsof&#39;找到锁定过程。
编辑:经过几次投票,我在linux和windows奴隶上实现了几个项目。
就我而言,我知道那些可能的僵尸的名字
我添加了特殊的工作/构建,可以杀死可能留在linux中的进程
在Windows中,我编写了CS程序来杀死可能的进程和/或运行“UnLock IT&#39;它与詹金斯的工作也可以释放资源。
答案 2 :(得分:4)
此页面仍然吸引了很多注意力,这可能是我最初问题的正确答案。
我遇到了同样的问题,在其中找到了一些具有root:root权限的文件 工作区目录。运行“ sudo chown -R jenkins:jenkins / var / lib / jenkins / workspace”解决了该问题。
答案 3 :(得分:0)
作为临时解决方案,请尝试重命名项目。
答案 4 :(得分:0)
我也遇到类似的问题。问题的原因是我将Jenkins工作区安装到docker并执行python代码,它创建了具有不同权限的Pycache
可执行文件,Jenkins无法删除它。
此问题的临时解决方法是删除git clone命令,然后使用sudo rm -rf code_directory
然后进行构建。它将删除所有代码。
然后恢复git clone和所有其他命令
答案 5 :(得分:0)
我删除了目录并重试。为我工作。
答案 6 :(得分:0)
我删除了工作区目录中的目录,重新运行作业,问题解决了。
答案 7 :(得分:0)
就我而言,我有一个错误
<块引用>引起:jenkins.util.io.CompositeIOException:无法删除“/home/jenkins/workspace/my_project”。试了3次
但实际上,当我通过 ssh 连接到该文件夹时,它是空的。
有问题的文件夹的真实位置是
<块引用>/media/jenkins_home/workspace/my_project
当我在那里删除并重新启动构建时,一切都成功了。
/home/jenkins/workspace/
绝对不是符号链接,我仍然不明白为什么错误日志中的文件夹不同,但猜测它与 Docker 卷或 smth 相关..
答案 8 :(得分:0)
我遇到了同样的问题,在工作区目录中找到了一些具有 root:root 权限的文件。尝试运行 find 。 -user root -exec chmod 777 {} ;更改文件的权限,但由于一些悬空的符号链接而失败。尝试通过“find -xtype l -delete”删除悬空的符号链接,但对于某些符号链接也失败了(因为那些符号给出了太多级别的符号链接)
运行“sudo chown -R jenkins:jenkins /var/lib/jenkins/workspace”解决了问题。