Maven目录:权限被拒绝

时间:2019-04-15 05:57:20

标签: linux maven jenkins

我已经在Linux服务器上安装了Maven和Jenkins。 Maven的腻子效果非常好。但是从Jenkins尝试使用Maven运行管道作业时,出现以下错误:/data1/SOA/app/oracle/product/middleware/Oracle_Home/oracle_common/modules/org.apache.maven_3.2.5/bin/ mvn:权限被拒绝

管道代码如下:

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/)
      }
   }
}

控制台输出:

    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/script.sh: 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

在腻子中,我使用以下命令检查了权限:

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

这里权限表明它有权执行此文件。但是仍然从詹金斯那里,我得到了“权限被拒绝”错误。

感谢您的提前答复。

2 个答案:

答案 0 :(得分:0)

添加bash命令以如下所示打印mvn的当前用户/组和文件权限。 这样的信息可以帮助确认用户/组和文件权限是否正确。

stage('Build') {
  if (isUnix()) {
     sh """
       # print current user, group
       id

       # print folder's user group/access
       ls -l "${mvnHome}"/..
       ls -l "${mvnHome}"

       "${mvnHome}"/bin/mvn --version
     """
  } else {
     bat(/"${mvnHome}\bin\mvn" --version/)
  }
}

答案 1 :(得分:0)

感谢您的所有回复。

我能够通过将Jenkins配置为root用户来解决此问题。我按照此链接中给出的步骤进行操作:Run shell command in jenkins as root user?

以下过程适用于CentOS:

  1. 打开此脚本(使用VIM或其他编辑器):

    vim / etc / sysconfig / jenkins

  2. 找到此$ JENKINS_USER并更改为“ root”:

    $ JENKINS_USER =“ root”

  3. 然后更改Jenkins主页,webroot和日志的所有权:

    chown -R root:root / var / lib / jenkins chown -R root:root / var / cache / jenkins chown -R root:root / var / log / jenkins