Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-40484

Unable to use withMaven() step inside docker container for old versions of Docker

      I'm not able to use withMaven step inside docker container.

      [Pipeline] withMaven
      $ docker exec ffff env printenv MAVEN_HOME
      $ docker exec ffff env printenv M2_HOME
      $ docker exec ffff env /bin/sh -c "which mvn"
      Using maven exec: /opt/apache-maven-3.3.9/bin/mvn
      Using global settings config with name MavenGlobal
      Replacing all maven server entries not found in credentials list is false
      [Pipeline] {
      [Pipeline] sh
      
      [test-XXX] Running shell script
      nohup: failed to run command `sh': No such file or directory
      
      [Pipeline] }
      [Pipeline] // withMaven

      My Jenkinsfile pipeline:

      node('docker') {
          stage('Checkout') {
              checkout scm
          }
          buildInDocker('linux') {
              stage('Maven') {
                  withMaven(globalMavenSettingsConfig: '11111111-2222-3333-4444-555555555555') {
                          sh 'mvn clean test'
                  }
              }
          }
      }

      It looks like PATH env gets overwritten.

          [JENKINS-40484] Unable to use withMaven() step inside docker container for old versions of Docker

          Test User created issue -
          dan tran made changes -
          Priority Original: Minor [ 4 ] New: Critical [ 2 ]
          dan tran made changes -
          Priority Original: Critical [ 2 ] New: Major [ 3 ]

          dan tran added a comment -

          Love to see this fixed

          dan tran added a comment - Love to see this fixed

          Same here, with this simple use case:

          node('master') {
              docker.image('maven').inside {
                  withMaven {
                      sh 'mvn -version'
                  }
              }
          }
          

          Bruno Meneguello added a comment - Same here, with this simple use case: node( 'master' ) { docker.image( 'maven' ).inside { withMaven { sh 'mvn -version' } } }

          Alvaro Lobato added a comment -

          Does this work for you?

          node('master') {
              docker.image('maven').inside {
                      sh 'mvn -version'
              }
          }
          

          Alvaro Lobato added a comment - Does this work for you? node( 'master' ) { docker.image( 'maven' ).inside { sh 'mvn -version' } }

          Yes, it does

          Bruno Meneguello added a comment - Yes, it does

          Test User added a comment -

          Simple Jenkinsfile to show how env are changed:

          node('docker') {
              docker.image('linux').inside {
                  echo 'env.PATH=' + env.PATH
                  sh 'echo $PATH > path'
                  path = readFile('path')
                  echo 'PATH=' + path
                  withMaven {
                      echo 'env.PATH.mvn=' + env.PATH
                      env.PATH = env.PATH + ':/bin'
                      sh 'echo $PATH > path_mvn'
                      path_mvn = readFile('path_mvn')
                      echo 'PATH.mvn=' + path_mvn
                      }
              }
          }
          env.PATH=/usr/local/bin:/usr/bin
          PATH=/opt/apache-maven-3.3.9/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
          env.PATH.mvn=/var/lib/jenkins/workspace/repository-test_develop-ISA36EXDSAND7KY74323XF3CUR2ZV65I43UWYEDK2UMP3I5UQYMQ@tmp/withMavenaf31c1e4:/usr/local/bin:/usr/bin
          PATH.mvn=/var/lib/jenkins/workspace/repository-test_develop-ISA36EXDSAND7KY74323XF3CUR2ZV65I43UWYEDK2UMP3I5UQYMQ@tmp/withMavenaf31c1e4:/var/lib/jenkins/workspace/repository-test_develop-ISA36EXDSAND7KY74323XF3CUR2ZV65I43UWYEDK2UMP3I5UQYMQ@tmp/withMavenaf31c1e4:/usr/local/bin:/usr/bin:/bin

          Test User added a comment - Simple Jenkinsfile to show how env are changed: node( 'docker' ) { docker.image( 'linux' ).inside { echo 'env.PATH=' + env.PATH sh 'echo $PATH > path' path = readFile( 'path' ) echo 'PATH=' + path withMaven { echo 'env.PATH.mvn=' + env.PATH env.PATH = env.PATH + ':/bin' sh 'echo $PATH > path_mvn' path_mvn = readFile( 'path_mvn' ) echo 'PATH.mvn=' + path_mvn } } } env.PATH=/usr/local/bin:/usr/bin PATH=/opt/apache-maven-3.3.9/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin env.PATH.mvn=/ var /lib/jenkins/workspace/repository-test_develop-ISA36EXDSAND7KY74323XF3CUR2ZV65I43UWYEDK2UMP3I5UQYMQ@tmp/withMavenaf31c1e4:/usr/local/bin:/usr/bin PATH.mvn=/ var /lib/jenkins/workspace/repository-test_develop-ISA36EXDSAND7KY74323XF3CUR2ZV65I43UWYEDK2UMP3I5UQYMQ@tmp/withMavenaf31c1e4:/ var /lib/jenkins/workspace/repository-test_develop-ISA36EXDSAND7KY74323XF3CUR2ZV65I43UWYEDK2UMP3I5UQYMQ@tmp/withMavenaf31c1e4:/usr/local/bin:/usr/bin:/bin

          dan tran added a comment -

          relate to JENKINS-41339 ??

          dan tran added a comment - relate to JENKINS-41339 ??

          Nuno Costa added a comment - - edited

          The workaround to pass the variables from outside withMaven block, mentioned by Test User here works on a Jenkins 2.32.2 but not on Jenkins 2.46.

          Ubuntu 12.04
          Jenkins 2.32.2
          Pipeline Maven Plugin 0.5
          Durable Task Plugin 1.13

          CentOS 7
          Jenkins 2.46
          Pipeline Maven Plugin 0.5
          Durable Task Plugin 1.13

          Buildserver
          Ubuntu 14.04 + docker 1.13.1

          Buildserver
          CentOS7 + docker 1.13.1

          Docker image:
          Ubuntu 12.04
          Maven 3.1.1

          Nuno Costa added a comment - - edited The workaround to pass the variables from outside withMaven block, mentioned by Test User here works on a Jenkins 2.32.2 but not on Jenkins 2.46. Ubuntu 12.04 Jenkins 2.32.2 Pipeline Maven Plugin 0.5 Durable Task Plugin 1.13 CentOS 7 Jenkins 2.46 Pipeline Maven Plugin 0.5 Durable Task Plugin 1.13 Buildserver Ubuntu 14.04 + docker 1.13.1 Buildserver CentOS7 + docker 1.13.1 Docker image: Ubuntu 12.04 Maven 3.1.1

            Unassigned Unassigned
            testuser7 Test User
            Votes:
            13 Vote for this issue
            Watchers:
            25 Start watching this issue

              Created:
              Updated: