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

withMaven doesn't copy settings.xml to Docker container

      I've been trying to figure this for a while now and don't seem to understand what's wrong nor why. 

      We're trying to build a java project in a Docker container using `withMaven` and a configuration saved in `Manage Jenkins -> Managed Files -> Maven settings.xml`. This configuration has been working fine for months but yesterday it just stopped. Our builds are depending on artifacts which are deployed to a local repository and therefore all of our builds are now failing. 

      I've tried logging into the docker container while it's running and checking `~/.m2/settings.xml` but the file is not there. Not sure why it's not being copied, but it's not a permission issue as far as I can tell. 

      Our pipeline is quite trivial:

      pipeline {
          agent {
              docker {
                  image 'opensuse-custom-image-with-jdk-and-maven:latest'
              }
          }
          options {
              timeout(time: 2, unit: 'HOURS')
              disableConcurrentBuilds()
              skipDefaultCheckout()
          }
          stages {
              stage('Building...')
              {
                  steps {
                      withMaven(maven: 'maven-3.3.9', mavenSettingsConfig: 'redacted')
                      { 
                          sh "mvn -U clean install -Dmaven.test.failure.ignore=true"
                      }
                  }
              }
          }
      }
       

          [JENKINS-47805] withMaven doesn't copy settings.xml to Docker container

          Brian Curtich added a comment -

          We faced the exact same issue. However, the settings file from the Config File Provider is not in ~/.m2/settings.xml, it lives on the workspace inside the container. I jumped in to the container and the settings file was in fact there, but it was as if withMaven was not able to detect it.

           

          The docker-workflow plugin was updated two days ago: https://plugins.jenkins.io/docker-workflow and it seems to be causing the issues with the Maven Pipeline Plugin. Downgrading the Docker Pipeline plugin from 1.14 to 1.13 solved the issue.

          Brian Curtich added a comment - We faced the exact same issue. However, the settings file from the Config File Provider is not in ~/.m2/settings.xml, it lives on the workspace inside the container. I jumped in to the container and the settings file was in fact there, but it was as if withMaven was not able to detect it.   The docker-workflow plugin was updated two days ago: https://plugins.jenkins.io/docker-workflow  and it seems to be causing the issues with the Maven Pipeline Plugin. Downgrading the Docker Pipeline plugin from 1.14 to 1.13 solved the issue.

          Steve Todorov added a comment -

          bcurtich thank you so much for pointing this out! I've been scratching my head for a while and was about to restore jenkins to an older backup we had! After downgrading Docker Pipeline to 1.13 everything works fine again!  

          Steve Todorov added a comment - bcurtich thank you so much for pointing this out! I've been scratching my head for a while and was about to restore jenkins to an older backup we had! After downgrading Docker Pipeline to 1.13 everything works fine again!  

          As bcurtich said, the docker-pipeline changed its behavior with version 1.14 and is no longer allowing plugins to contribute the "PATH" variables.

          The Pipeline Maven Plugin contributes to the PATH environment variable to specify the mvn command line arguments such as the settings file.

          https://github.com/jenkinsci/docker-workflow-plugin/commit/f55c122fe10f28bf31ccfca66f0587facf508148#diff-4d69c729a160747eba5c12ea83f7753cR248

          https://github.com/jenkinsci/pipeline-maven-plugin/blob/pipeline-maven-3.0.2/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution.java#L279

          Cyrille Le Clerc added a comment - As bcurtich said, the docker-pipeline changed its behavior with version 1.14 and is no longer allowing plugins to contribute the "PATH" variables. The Pipeline Maven Plugin contributes to the PATH environment variable to specify the mvn command line arguments such as the settings file. https://github.com/jenkinsci/docker-workflow-plugin/commit/f55c122fe10f28bf31ccfca66f0587facf508148#diff-4d69c729a160747eba5c12ea83f7753cR248 https://github.com/jenkinsci/pipeline-maven-plugin/blob/pipeline-maven-3.0.2/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution.java#L279

          bcurtich, stodorov can you please test 3.0.3-beta-1 and prepend the '$MVN_CMD' variable to the '$PATH' variable in each 'sh' step that invokes 'mvn'?

          https://github.com/jenkinsci/pipeline-maven-plugin/releases/tag/pipeline-maven-3.0.3-beta-1 ?

          node("linux-agent-with-docker") {
              docker.image('maven').inside {
                  withMaven(mavenSettingsConfig: 'my-maven-settings') {
          
                      git "https://github.com/cyrille-leclerc/my-jar.git"
          
                      // prepend the $MVN_CMD variable to the $PATH environment variable in each "sh" step that invokes mvn 
                      sh 'export PATH=$MVN_CMD:$PATH && mvn help:effective-settings'
                  }
              }
          }
          

          Cyrille Le Clerc added a comment - bcurtich , stodorov can you please test 3.0.3-beta-1 and prepend the '$MVN_CMD' variable to the '$PATH' variable in each 'sh' step that invokes 'mvn'? https://github.com/jenkinsci/pipeline-maven-plugin/releases/tag/pipeline-maven-3.0.3-beta-1 ? node( "linux-agent-with-docker" ) { docker.image( 'maven' ).inside { withMaven(mavenSettingsConfig: 'my-maven-settings' ) { git "https: //github.com/cyrille-leclerc/my-jar.git" // prepend the $MVN_CMD variable to the $PATH environment variable in each "sh" step that invokes mvn sh 'export PATH=$MVN_CMD:$PATH && mvn help:effective-settings' } } }

            cleclerc Cyrille Le Clerc
            stodorov Steve Todorov
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: