How to fix maven permission issue in Jenkins

  docker, jenkins, maven

I installed Jenkins as a docker container. In Jenkins Global Tool Configuration add MAVEN_HOME (/usr/share/maven) and check "Install automatically". When I press Build Now I go this error:

Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/MavenProject
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] Done
java.nio.file.AccessDeniedException: /usr/share/maven
    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)
    at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384)
    at java.nio.file.Files.createDirectory(Files.java:674)
    at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781)
    at java.nio.file.Files.createDirectories(Files.java:767)
    at hudson.FilePath.mkdirs(FilePath.java:3299)
    at hudson.FilePath.access$1300(FilePath.java:212)
    at hudson.FilePath$Mkdirs.invoke(FilePath.java:1252)
    at hudson.FilePath$Mkdirs.invoke(FilePath.java:1248)
    at hudson.FilePath.act(FilePath.java:1076)
    at hudson.FilePath.act(FilePath.java:1059)
    at hudson.FilePath.mkdirs(FilePath.java:1244)
    at hudson.FilePath.installIfNecessaryFrom(FilePath.java:907)
Caused: java.io.IOException: Failed to install https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip to /usr/share/maven...

I do not have /var/jenkins_home/workspace/MavenProject directory. And this directory is under root account with full permissions. Any idea how can I fix it?

Source: Docker Questions

LEAVE A COMMENT