marcelZ
marcelZ

Reputation: 101

java.nio.file.AccessDeniedException at Jenkins build

I'm setting up a Jenkins system at MacOSX Server for an automatically build after a svn checkin. But when the build is starting I get these java error at the console output. Does anyone have experience with Jenkins and these error?

Gestartet durch Benutzer anonymous
[EnvInject] - Loading node environment variables.
Baue in Workspace /Users/Shared/Jenkins/Home/jobs/myProject/workspace
Cleaning local Directory .
java.nio.file.AccessDeniedException: /Users/Shared/Jenkins/Home/jobs/my Project/workspace/./.svn/pristine/04/040d4cd4de48d844246c38e096a78718879bfafb.svn-base
	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.implDelete(UnixFileSystemProvider.java:244)
	at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
	at java.nio.file.Files.delete(Files.java:1126)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at hudson.Util.deleteFile(Util.java:255)
	at hudson.Util.deleteRecursive(Util.java:318)
	at hudson.Util.deleteContentsRecursive(Util.java:220)
	at hudson.Util.deleteRecursive(Util.java:309)
	at hudson.Util.deleteContentsRecursive(Util.java:220)
	at hudson.Util.deleteRecursive(Util.java:309)
	at hudson.Util.deleteContentsRecursive(Util.java:220)
	at hudson.Util.deleteRecursive(Util.java:309)
	at hudson.Util.deleteContentsRecursive(Util.java:220)
	at hudson.scm.subversion.CheckoutUpdater$1.perform(CheckoutUpdater.java:81)
	at hudson.scm.subversion.WorkspaceUpdater$UpdateTask.delegateTo(WorkspaceUpdater.java:162)
	at hudson.scm.SubversionSCM$CheckOutTask.perform(SubversionSCM.java:988)
	at hudson.scm.SubversionSCM$CheckOutTask.invoke(SubversionSCM.java:969)
	at hudson.scm.SubversionSCM$CheckOutTask.invoke(SubversionSCM.java:945)
	at hudson.FilePath.act(FilePath.java:990)
	at hudson.FilePath.act(FilePath.java:968)
	at hudson.scm.SubversionSCM.checkout(SubversionSCM.java:894)
	at hudson.scm.SubversionSCM.checkout(SubversionSCM.java:830)
	at hudson.scm.SCM.checkout(SCM.java:485)
	at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
	at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:607)
	at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
	at hudson.model.Run.execute(Run.java:1738)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:98)
	at hudson.model.Executor.run(Executor.java:410)
Sending e-mails to: m...
Finished: FAILURE

Upvotes: 10

Views: 50692

Answers (4)

valdeci
valdeci

Reputation: 15237

This problem is occurring because you don't have permission to execute the job on the Jenkins jobs directory (in your case /Users/Shared/Jenkins/Home/jobs) or you don't have permission on the Jenkins directory /var/lib/jenkins/.

I encountered the same issue when I tried to copy the jobs directory from one server to another.

To solve this, we need to change the owner of the jobs directory to the jenkins user:

sudo chown -R jenkins:jenkins /Users/Shared/Jenkins/Home/jobs

If this does not solve the problem, the issue might be with the permissions of your /var/lib/jenkins directory:

sudo chown -R jenkins:jenkins /var/lib/jenkins/

This should resolve your problem.

P.S. You may need to restart your Jenkins application.

Upvotes: 10

Affes Salem
Affes Salem

Reputation: 1651

If you have encountred this issue usually it's related to the user running the jenkins process and sometimes that user wouldn't be able to do some actions or access files so you will need to provide him with certain permissions as said above you can use chown or chmod like so:

# Change ownership to a whole directory
chmod -R user:group /path/to/dir
# Change ownership to a single file
chmod user:group /path/to/file
# Careful with the value after chmod
# You will need to only give what's needed
# Change ownership to a whole directory
chmod 744 -R /path/to/dir
# Change ownership to a single file
chmod 744 /path/to/file

An in your case since you're dealing with jenkins usually you can either find the directory of jenkins data under:

  • Default path: /var/lib/jenkins/
  • Env var (usually defined like that in a docker container): JENKINS_HOME=/var/jenkins_home
  • In case you have access to the configuration page, you can find it on the header as Home directory : http://localhost:8080/configure

Upvotes: 0

Praveen Muniraj
Praveen Muniraj

Reputation: 101

You need to modify the permission for jenkins user so that you can run the shell commands. Make root user of your machine as default user of jenkins, will slove your problem.

Following process is for CentOS

  1. Open up the this script (using VIM or other editor):

vim /etc/sysconfig/jenkins

  1. Find this $JENKINS_USER and change to “root”:

$JENKINS_USER="root"

  1. Then change the ownership of Jenkins home, webroot and logs:
chown -R root:root /var/lib/jenkins
chown -R root:root /var/cache/jenkins
chown -R root:root /var/log/jenkins
  1. Restart Jenkins and check the user has been changed:
service jenkins restart
ps -ef | grep jenkins

Upvotes: -3

Julien Charon
Julien Charon

Reputation: 610

Seems like the os user which is running jenkins has no write privileges for either the complete workspace directory or some of the files in the workspace directory.

Upvotes: 2

Related Questions