Maven directory : Permission denied

I have installed Maven and Jenkins in my linux server. Maven is executing perfectly fine from putty. But from Jenkins when I am trying to run the pipeline job with maven I am getting the following error: /data1/SOA/app/oracle/product/middleware/Oracle_Home/oracle_common/modules/org.apache.maven_3.2.5/bin/mvn : Permission denied

The pipeline code is as below:

node {
   def mvnHome
   stage('Preparation') { 
      git branch: 'master', url: "http://UN:PW@IP/root/Test-Repo.git", credentialsId: 'QPGitCred'      
      mvnHome = tool 'org.apache.maven_3.2.5'
   stage('Build') {
      if (isUnix()) {
         sh "'${mvnHome}/bin/mvn' --version"
      } else {
         bat(/"${mvnHome}\bin\mvn" --version/)

Console Output:

    Started by user jenkins_dev Running in Durability level: MAX_SURVIVABILITY [Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in /var/lib/jenkins/workspace/PipelineJob1 [Pipeline] { [Pipeline] stage [Pipeline] { (Preparation) [Pipeline] git using credential QPGitCred
     git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository
     git config remote.origin.url http://UN:PW@IP/root/Test-Repo.git # timeout=10 Fetching upstream changes from http://UN@IP/root/Test-Repo.git
     git --version # timeout=10 using GIT_ASKPASS to set credentials QPGitCred
     git fetch --tags --progress http://UN@IP/root/Test-Repo.git +refs/heads/*:refs/remotes/origin/*
     git rev-parse refs/remotes/origin/master^{commit} # timeout=10
     git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10 Checking out Revision 0051ce3ezza8457e44e890c1cad8z2c93de19bd0 (refs/remotes/origin/master)
     git config core.sparsecheckout # timeout=10
     git checkout -f 0051ce3rrda8457e44e890c1cad8f2z93de19bd0
     git branch -a -v --no-abbrev # timeout=10
     git branch -D master # timeout=10
     git checkout -b master 0051ce3ebda8457e44e890c1cad8f2c49de19bd0 Commit message: "Update pom.xml"
     git rev-list --no-walk 0051ce3ebda8121e44h890c1cuy8f2c93de19bd0 # timeout=10 [Pipeline] tool [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Build) [Pipeline] isUnix [Pipeline] sh
    + /data1/SOA/app/oracle/product/middleware/Oracle_Home/oracle_common/modules/org.apache.maven_3.2.5/bin/mvn
    --version /var/lib/jenkins/workspace/PipelineJob1@tmp/durable-990d0f84/ line 1: 
/data1/SOA/app/oracle/product/middleware/Oracle_Home/oracle_common/modules/org.apache.maven_3.2.5/bin/mvn: Permission denied [Pipeline] } 
[Pipeline] // stage [Pipeline] } [Pipeline] 
// node [Pipeline] End of 
Pipeline ERROR: script returned exit code 1 Finished: FAILURE

From putty I checked permission with below command :

ls -l /data1/SOA/app/oracle/product/middleware/Oracle_Home/oracle_common/modules/org.apache.maven_3.2.5/bin/mvn

-rwxrwxrwx 1 testusr dba 5543 Dec 14  2014 /data1/SOA/app/oracle/product/middleware/Oracle_Home/oracle_common/modules/org.apache.maven_3.2.5/bin/mvn

Here permission shows it has right to execute this file. But still from Jenkins I am getting Permission denied error.

Thanks for your response in advance.

1 answer

  • answered 2019-04-15 13:08 yong

    Add bash command to print current user/group and file right of mvn as following. Such info can help to confirm the user/group and file right are as expect.

    stage('Build') {
      if (isUnix()) {
         sh """
           # print current user, group
           # print mvn file right
           ls -l "${mvnHome}"/bin/mvn
           "${mvnHome}"/bin/mvn --version
      } else {
         bat(/"${mvnHome}\bin\mvn" --version/)