web-dev-qa-db-ja.com

ジェンキンスが突然ワークスペースを削除できなくなるのはなぜですか

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
17
MarkA

ワークスペースのファイルまたはディレクトリをロックしているものがあります。

  • 誰かがJenkinsにログインし、Jenkins経由ではなく、ファイルシステムを使用してワークスペースから直接ファイルにアクセスしています。
  • ビルドプロセスはゾンビプログラムを残しました。

他のいくつかの同様のケース。

FSへのシェルアクセス権がある場合は、lsofのようなものを使用してロックプロセスを見つけます。

編集:いくつかの投票の後、いくつかのLinuxおよびWindowsスレーブにいくつかのアイテムを実装しました。私の場合、私は可能なゾンビの名前を知っています。
Linuxに残っている可能性のあるプロセスを強制終了する特別なジョブ/ビルドを追加しました。
Windowsで、可能性のあるプロセスを強制終了したり、リソースを解放するJenkinsジョブで「UnLock IT」を実行したりするCSプログラムを作成しました。

14
KSI

私はついにすべてを説明する解決策を見つけました。

原因: Jenkins内でdockerを使用し、DockerにJenkins作業ディレクトリをマウントしました(-v pwd:/code:rw)。実行時に私のプログラムはいくつかのファイルを生成しますが、これらのファイルはマウントされるとJenkinsの作業ディレクトリにも配置されます。ただし、ユーザーはJenkinsユーザーではなくdocker rootです。Jenkinsユーザーはこれらのファイルを削除できず、このエラーが発生するためです。

ソリューション:Jenkinsユーザーをdockerと共有することもできるため、作成されるすべてのファイルは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
4
Sudhanshu Patel

一時的な解決策として、プロジェクトの名前を変更してみてください。

2
Vince Twano

同様の問題が発生しています。問題の原因は、Jenkinsワークスペースをdockerにマウントしてpythonコードを実行することです。これにより、異なる権限を持ついくつかのPycache実行可能ファイルが作成され、Jenkinsはそれを削除できません。

これに対する一時的な修正は、git cloneコマンドを削除し、Sudo rm -rf code_directoryを使用してビルドすることです。すべてのコードを削除します。次にgit cloneと他のすべてのコマンドを復元します

1
Sudhanshu Patel