背景:打算清理 Jenkins 的缓存,所以用 rm -rf 命令删除了 workspace,其实删除里面的东西就可了,不必删除整个文件夹
现状:重新构建时报错
11:57:52 java.nio.file.AccessDeniedException: /var/lib/jenkins/workspace/demo-service
11:57:52 at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
11:57:52 at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
11:57:52 at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
11:57:52 at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384)
11:57:52 at java.nio.file.Files.createDirectory(Files.java:674)
11:57:52 at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781)
11:57:52 at java.nio.file.Files.createDirectories(Files.java:767)
11:57:52 at hudson.FilePath.mkdirs(FilePath.java:3609)
11:57:52 at hudson.FilePath.access 1100 ( F i l e P a t h . j a v a : 212 ) 11 : 57 : 52 a t h u d s o n . F i l e P a t h 1100(FilePath.java:212) 11:57:52 at hudson.FilePath 1100(FilePath.java:212)11:57:52athudson.FilePathMkdirs.invoke(FilePath.java:1384)
11:57:52 at hudson.FilePath M k d i r s . i n v o k e ( F i l e P a t h . j a v a : 1379 ) 11 : 57 : 52 a t h u d s o n . F i l e P a t h . a c t ( F i l e P a t h . j a v a : 1200 ) 11 : 57 : 52 a t h u d s o n . F i l e P a t h . a c t ( F i l e P a t h . j a v a : 1183 ) 11 : 57 : 52 a t h u d s o n . F i l e P a t h . m k d i r s ( F i l e P a t h . j a v a : 1374 ) 11 : 57 : 52 a t h u d s o n . m o d e l . A b s t r a c t P r o j e c t . c h e c k o u t ( A b s t r a c t P r o j e c t . j a v a : 1209 ) 11 : 57 : 52 a t h u d s o n . m o d e l . A b s t r a c t B u i l d Mkdirs.invoke(FilePath.java:1379) 11:57:52 at hudson.FilePath.act(FilePath.java:1200) 11:57:52 at hudson.FilePath.act(FilePath.java:1183) 11:57:52 at hudson.FilePath.mkdirs(FilePath.java:1374) 11:57:52 at hudson.model.AbstractProject.checkout(AbstractProject.java:1209) 11:57:52 at hudson.model.AbstractBuild Mkdirs.invoke(FilePath.java:1379)11:57:52athudson.FilePath.act(FilePath.java:1200)11:57:52athudson.FilePath.act(FilePath.java:1183)11:57:52athudson.FilePath.mkdirs(FilePath.java:1374)11:57:52athudson.model.AbstractProject.checkout(AbstractProject.java:1209)11:57:52athudson.model.AbstractBuildAbstractBuildExecution.defaultCheckout(AbstractBuild.java:645)
11:57:52 at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)
11:57:52 at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:517)
11:57:52 at hudson.model.Run.execute(Run.java:1896)
11:57:52 at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
11:57:52 at hudson.model.ResourceController.execute(ResourceController.java:101)
11:57:52 at hudson.model.Executor.run(Executor.java:442)
重新创建 workspace 文件夹,依旧报错
原因:workspace 文件夹是由 root 账号所创,而 Jenkins 操作 workspace 的写入用的是叫 jenkins 的用户
解决办法 :
- 给 workspace 文件夹授权
- 给 jenkins 用户赋予 workspace 的权限
chown -R jenkins /var/lib/jenkins/workspace/
chown -R jenkins:jenkins workspace