Search code examples
linuxjenkinspermission-denied

Jenkins console shows permission denied error when I run the test.sh file


I have created one .sh which contains java command required to run the tesng.XML file when I run this test.sh file on Jenkins it shows me permission denied error.

Jenkins console output:

Building in workspace /home/dev2/eclipse-workspace/weeklytask
[weeklytask] $ /bin/sh -xe /tmp/jenkins7439378074963422991.sh
+ ./test.sh
[TestNG] Running:
  /home/dev2/eclipse-workspace/weeklytask/enquiryreminder.xml

Starting ChromeDriver 2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7) on port 8120
Only local connections are allowed.

FOLLOW UP REMINDER CRON WEEKLY CHECK TESTCASE FAILED 
PLEASE CHECK THE TIME INTERVAL SETTING 
SET THE TIME INTERVAL TO 600 
FOLLOW UP REMINDER CRON WEEKLY CHECK TESTCASE FAILED 
PLEASE CHECK THE TIME INTERVAL SETTING 
SET THE TIME INTERVAL TO 600 
[[Utils]] Error while writing to /home/dev2/eclipse-workspace/weeklytask/test-output/Suite/Test.html: /home/dev2/eclipse-workspace/weeklytask/test-output/Suite/Test.html (**Permission denied**)
[[Utils]] Error while writing to /home/dev2/eclipse-workspace/weeklytask/test-output/Suite/Test.xml: /home/dev2/eclipse-workspace/weeklytask/test-output/Suite/Test.xml (Permission denied)

===============================================
Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

[[Utils]] Error while writing to test-output/junitreports/TEST-verify.enquiryremindertest.xml: test-output/junitreports/TEST-verify.enquiryremindertest.xml (Permission denied)

Solution

  • Jenkins use the user jenkins. If you have created your file with other user, there might be permission issue on the file. To resolve change the permission on the files and allow other users to execute the script. You can use

    chmod +x test.sh
    

    The directory eclipse-workspace belongs to dev2 user and here jenkins user is trying to write data in it. Give jenkins write permission on this folder. try

    sudo chmod -R a+rw /home/dev2/eclipse-workspace
    

    For more details about permission you can view This tutorial