';java.nio.file.AccessDeniedException:/home/jenkins/workspace/testCases/41/1/1.in';通过jenkins管道删除文件时

';java.nio.file.AccessDeniedException:/home/jenkins/workspace/testCases/41/1/1.in';通过jenkins管道删除文件时,java,jenkins,Java,Jenkins,我在linux主机上有一个jenkins服务器。我尝试使用jenkins dashboard中的jenkins管道删除一些文件。我的管道脚本如下所示: node(){ int deleteCount=0 while(deleteCount < 10) { try{ deleteCount++ sh script:'rm -rf ../testCases/41/*'

我在linux主机上有一个jenkins服务器。我尝试使用jenkins dashboard中的jenkins管道删除一些文件。我的管道脚本如下所示:

node(){
      int deleteCount=0
      while(deleteCount < 10)
      {
         try{
             deleteCount++
             sh script:'rm -rf ../testCases/41/*'
             boolean fileExist = fileExists '../testCases/41/1/1.in'
             if(!fileExist) break
         }catch(err)
         {
            sleep 1
         }
}
writeFile file: '../testCases/41/1/1.in', text: 'bookstore'
writeFile file: '../testCases/41/1/1.out', text: 'databaseName:bookstore'
writeFile file: '../testCases/41/1/1.isPublic', text: '1'
writeFile file: '../testCases/41/1/2.in', text: 'bookstore2'
writeFile file: '../testCases/41/1/2.out', text: 'databaseName:bookstore2'
writeFile file: '../testCases/41/1/2.isPublic', text: '1'
writeFile file: '../testCases/41/2/1.in', text: 'book\n5\nid int(11)\nauthor 
varchar(255)\ntitle varchar(255)\npublisher varchar(255)\npublihserYear 
int(11)'
writeFile file: '../testCases/41/2/1.out', text: 'table:book'
writeFile file: '../testCases/41/2/1.isPublic', text: '1'
writeFile file: '../testCases/41/2/2.in', text: 'book2\n3\nid int(11)\ntitle 
varchar(255)\nprice int(11)'
writeFile file: '../testCases/41/2/2.out', text: 'table:book2'
writeFile file: '../testCases/41/2/2.isPublic', text: '1'
........

我只想在写入新数据之前删除旧文件,但这个问题真的让我很困惑。

权限被拒绝意味着你没有该文件夹的权限,也许你不是它们的所有者?您能以root用户身份运行该命令吗?

很明显,Jenkins对这些文件没有权限。 有一次我通过临时使用root用户运行jenkins进行测试,就遇到了这个问题

转到Jenkins配置文件(Red-Hat-/etc/sysconfig/Jenkins),查看运行Jenkins的用户。无法删除的文件可能属于其他用户


使用合适的用户手动删除这些文件,您应该会很好。

是的,我在root中启动了jenkins,并为所有文件授予了777权限。有些情况下,我可以成功删除文件,但有时无法
1
+ rm -rf ../testCases/41
rm: can't remove '../testCases/41/1/1.in': Permission denied
rm: can't remove '../testCases/41/1/1.out': Permission denied
rm: can't remove '../testCases/41/1/1.isPublic': Permission denied
rm: can't remove '../testCases/41/1/2.in': Permission denied
rm: can't remove '../testCases/41/1/2.out': Permission denied
rm: can't remove '../testCases/41/1/2.isPublic': Permission denied
rm: can't remove '../testCases/41/1': Permission denied
rm: can't remove '../testCases/41/2/1.in': Permission denied
rm: can't remove '../testCases/41/2/1.out': Permission denied
rm: can't remove '../testCases/41/2/1.isPublic': Permission denied
rm: can't remove '../testCases/41/2/2.in': Permission denied
rm: can't remove '../testCases/41/2/2.out': Permission denied
rm: can't remove '../testCases/41/2/2.isPublic': Permission denied
rm: can't remove '../testCases/41/2': Permission denied
rm: can't remove '../testCases/41/3/1.in': Permission denied
.......`1`


[Pipeline] sleep
Sleeping for 1 sec
[Pipeline] writeFile
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.nio.file.AccessDeniedException: 
/home/jenkins/workspace/testCases/41/1/1.in
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
atsun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.ja
 va:214)
.....
at hudson.FilePath$37.invoke(FilePath.java:1912)
at hudson.FilePath$37.invoke(FilePath.java:1908)
at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2739)
at hudson.remoting.UserRequest.perform(UserRequest.java:153)
at hudson.remoting.UserRequest.perform(UserRequest.java:50)
at hudson.remoting.Request$2.run(Request.java:336)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at hudson.remoting.Engine$1$1.run(Engine.java:94)
at java.lang.Thread.run(Thread.java:745)
at ......remote call to Channel to /10.9.186.111(Native Method)
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1545)
at hudson.remoting.UserResponse.retrieve(UserRequest.java:253)
at hudson.remoting.Channel.call(Channel.java:830)
at hudson.FilePath.act(FilePath.java:986)
Caused: java.io.IOException: remote file operation failed: /home/jenkins/workspace/testCases/41/1/1.in at hudson.remoting.Channel@63880c2b:Channel to /10.9.186.111
at hudson.FilePath.act(FilePath.java:993)
at hudson.FilePath.act(FilePath.java:975)
at hudson.FilePath.write(FilePath.java:1908)
at org.jenkinsci.plugins.workflow.steps.WriteFileStep$Execution.run(WriteFileStep.java:94)
at org.jenkinsci.plugins.workflow.steps.WriteFileStep$Execution.run(WriteFileStep.java:84)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49)
at hudson.security.ACL.impersonate(ACL.java:260)
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:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE