Docker Container Jenkins管道脚本:执行脚本时拒绝权限

时间:2019-06-25 11:05:58

标签: docker jenkins jenkins-pipeline dockerfile ubuntu-18.04

我正在docker容器中运行jenkins。我创建了一个简单的pipleline来检出,构建和运行docker image,但是出现以下错误。

下面是我的pipleline脚本:

node {
   def mvnHome = tool name: 'Maven Path', type: 'maven'
   stage('Git CheckOut') {
     git branch: '2019_DOCKER_SERVICES', credentialsId: 'git-creds', url: 'http://10.10.10.84:8111/scm/git/JEE_M_SERVICES'
   }
    stage('Maven Build') {
      // Run the maven build
      withEnv(["MVN_HOME=$mvnHome"]) {
         if (isUnix()) {
            sh '"$MVN_HOME/bin/mvn" -f Services/user-service/pom.xml clean install'
         } else {
          // bat(/"%MVN_HOME%\bin\mvn" -f Services\\user-service\\pom.xml clean install/)
         }
      }
  }
   stage('Docker Image Build') {
     sh '"Services/user-service/" docker build -t user-service'
   }


}

但是我在最后一个阶段遇到了跟随错误,前两个阶段运行成功。

[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Docker Image Build)
[Pipeline] sh
+ Services/user-service/ docker build -t user-service
/var/jenkins_home/jobs/docker-demo/workspace@tmp/durable-a5c035cf/script.sh: 1: /var/jenkins_home/jobs/docker-demo/workspace@tmp/durable-a5c035cf/script.sh: Services/user-service/: Permission denied
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

1 个答案:

答案 0 :(得分:0)

  1. 您必须设置新的J enkins slaves using Docker
  2. 在Docker容器中运行Docker很奇怪
  3. 要访问低级操作,您必须run your Docker container privilege d