Issue
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?
Solution
It means that inside the container, the user account Jenkins is running under does not have write permissions to /usr/share/maven
to write the downloaded version of maven. Either the directory doesn't exist, or it is probably owned by root.
You can either create this directory manually by starting an interactive shell on the container as root:
docker exec -u 0 -ti name_of_container sh
And then on this shell (not on the host machine!)
mkdir -p /usr/share/maven
chmod 777 /usr/share/maven
Or in your Dockerfile
RUN mkdir -p /usr/share/maven
RUN chmod 777 /usr/share/maven
These examples are just for simplicity, it's better to just add permissions for the Jenkins user or group to that directory.
Answered By - Mzzl
Answer Checked By - Marilyn (JavaFixing Volunteer)