0

I want to run the testng.xml file in Jenkins. I am using the custom workspace and I added Execute Shell as a build step.

I am writing the following command to Execute Shell:

java -cp "./*:bin" org.testng.TestNG testng.xml 

All the required jar files and testng.xml file is inside /home/wonderbiz/Documents/JarFolder

When I am clicking on build now I am getting this exception.

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

3

Run command as a root user or Change the permission of the root directory that you want to access e.g. here /home/wonderbiz/Documents/JarFolder so use command

$ sudo su
# chmod -R 777 /home

But i would recommend you to create own directory and then modify the permission of that directory. e.g.

# mkdir /demo

Copy required file to that directory(/demo) and do the configuration setting then try to run.

  • Please do not recommend apply full read/write/execute permissons over directories in a system. Check this solution instead https://stackoverflow.com/a/56059969/3284482 – Mauricio Jul 02 '21 at 17:27
0

This error message...

java.nio.file.AccessDeniedException: /home/wonderbiz/Documents
    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.checkAccess(UnixFileSystemProvider.java:308)
    at java.nio.file.Files.createDirectories(Files.java:746)
    at hudson.FilePath.mkdirs(FilePath.java:3239)

...implies that the Jenkins was unable to access/create the sub-directory /home/wonderbiz/Documents.

This issue can raise in either/all of the below mentioned cases:

  1. checkAccess error is generally caused because of either insufficient permissions or someother process locking the file. In this usecase it seems that the folder that Jenkins unsuccessfully tried to access was already present. The folder and all the files beneath were present even before the execution was triggered.
  2. Parent directory (/home/wonderbiz/Documents) needs to have at least rx for non-owner to list its content and w to make changes there, regardless of subdirectory permissions. Change the permission of the /home/wonderbiz/Documents/JarFolder directory

    chmod -R 777 /home
    
  3. A better approach would have to create dedicated directory eg. in /opt and use that.

  4. This problem can also ocurr because Jenkins don't have permission to execute job with in /home/wonderbiz/Documents sub-directory. Go to Jenkins Config file (Red Hat - /etc/sysconfig/jenkins), and see which user you are using to run Jenkins). To solve this you need to change the owner of jobs to the jenkins user:

    sudo chown -R jenkins:jenkins /home/wonderbiz/Documents (need to restart Jenkins)
    
  5. It appears 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.


Outro

You can find a relevant discussion in Need correct step for Bat file creation using (TestNG.xml + Maven)

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Same comment here : Please do not recommend apply full read/write/execute permissons over directories in a system. Check this solution instead https://stackoverflow.com/a/56059969/3284482 – Mauricio Jul 02 '21 at 17:28