[JIRA] (JENKINS-40484) Unable to use withMaven step inside docker container

186 views
Skip to first unread message

frut3k7@gmail.com (JIRA)

unread,
Dec 15, 2016, 12:13:04 PM12/15/16
to jenkinsc...@googlegroups.com
Test User created an issue
 
Jenkins / Bug JENKINS-40484
Unable to use withMaven step inside docker container
Issue Type: Bug Bug
Assignee: Alvaro Lobato
Components: pipeline-maven-plugin
Created: 2016/Dec/15 5:12 PM
Environment: Jenkins 2.36, Pipeline Maven Plugin 0.4
Priority: Minor Minor
Reporter: Test User

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.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

dantran@gmail.com (JIRA)

unread,
Dec 28, 2016, 1:07:03 AM12/28/16
to jenkinsc...@googlegroups.com
dan tran updated an issue
Change By: dan tran
Priority: Minor Critical

dantran@gmail.com (JIRA)

unread,
Dec 28, 2016, 2:00:02 AM12/28/16
to jenkinsc...@googlegroups.com
dan tran updated an issue
Change By: dan tran
Priority: Critical Major

dantran@gmail.com (JIRA)

unread,
Jan 3, 2017, 6:27:01 AM1/3/17
to jenkinsc...@googlegroups.com

jenkins-ci.org@meneguello.com (JIRA)

unread,
Jan 3, 2017, 8:38:01 AM1/3/17
to jenkinsc...@googlegroups.com

Same here, with this simple use case:

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

alobato@cloudbees.com (JIRA)

unread,
Jan 9, 2017, 6:44:01 AM1/9/17
to jenkinsc...@googlegroups.com

Does this work for you?

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

jenkins-ci.org@meneguello.com (JIRA)

unread,
Jan 10, 2017, 9:24:01 AM1/10/17
to jenkinsc...@googlegroups.com

frut3k7@gmail.com (JIRA)

unread,
Jan 12, 2017, 8:55:01 AM1/12/17
to jenkinsc...@googlegroups.com

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

dantran@gmail.com (JIRA)

unread,
Feb 5, 2017, 1:04:02 PM2/5/17
to jenkinsc...@googlegroups.com

ncosta@fgtsa.com (JIRA)

unread,
Feb 24, 2017, 10:09:04 AM2/24/17
to jenkinsc...@googlegroups.com

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 14.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

ncosta@fgtsa.com (JIRA)

unread,
Mar 1, 2017, 7:24:01 AM3/1/17
to jenkinsc...@googlegroups.com
Nuno Costa edited a comment on Bug JENKINS-40484
The workaround to pass the variables from outside withMaven block, mentioned by Test User [here|https://issues.jenkins-ci.org/browse/JENKINS-40484?focusedCommentId=283081&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-283081] works on a Jenkins 2.32.2 but not on Jenkins 2.46.

Ubuntu
14 12 .04

Jenkins 2.32.2
Pipeline Maven Plugin 0.5
Durable Task Plugin 1.13

Centos 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

ncosta@fgtsa.com (JIRA)

unread,
Mar 1, 2017, 7:44:01 AM3/1/17
to jenkinsc...@googlegroups.com

This can be replicated with below code.
Commented is some troubleshoot steps.
Can be resolved by getting the container path into a variable and pass that to withEnv.
Be aware that echo adds a new line to the file and in my case, this was also triggering the same issue. Use trim() to remove the extra line.
Use of printf instead of echo will avoid the trim() usage.

CentOS 7
Jenkins 2.46

parallel(
    number1: {
        node('centos-buildserver') {
            buildenv = docker.image("custom-ubuntu12.04-maven")
            buildenv.inside("-v /var/lib/jenkins/.m2/repository/${EXECUTOR_NUMBER}:/home/jenkins/.m2/repository"){
                stage("test") {
                    /*sh 'echo $PATH > path'
                    sh 'printf $PATH > path'
                    path = readFile('path').trim()
                    path = readFile('path')
                    pathtrim = readFile('path').trim()
                    echo '#######'
                    echo 'no trim: #'+path+'#'
                    echo '#######'
                    echo 'with trim: #'+pathtrim+'#'
                    echo '#######'*/
                    sh 'ls -l'
                    //withEnv(['PATH+workaround='+path]) {
                        withMaven(mavenSettingsConfig: 'settings-id'){
                            echo 'inside withmaven'
                            sh 'ls -l'
                        }
                    //}
                }
            }
        }
    },
    number2: {
        node('ubuntu-buildserver') {
            buildenv = docker.image("custom-ubuntu12.04-maven")
            buildenv.inside("-v /var/lib/jenkins/.m2/repository/${EXECUTOR_NUMBER}:/home/jenkins/.m2/repository"){
                stage("test") {
                    /*sh 'echo $PATH > path'
                    sh 'printf $PATH > path'
                    path = readFile('path').trim()
                    path = readFile('path')
                    pathtrim = readFile('path').trim()
                    echo '#######'
                    echo '#'+path+'#'
                    echo '#######'
                    echo '#'+pathtrim+'#'
                    echo '#######'*/
                    sh 'ls -l'
                    //withEnv(['PATH+workaround='+path]) {
                        withMaven(mavenSettingsConfig: 'settings-id'){
                            echo 'inside withmaven'
                            sh 'ls -l'
                        }
                    //}
                }
            }
        }
    }
)

ncosta@fgtsa.com (JIRA)

unread,
Mar 1, 2017, 7:58:01 AM3/1/17
to jenkinsc...@googlegroups.com
Nuno Costa edited a comment on Bug JENKINS-40484
This can be replicated with below code. CentOS node build will fail with
{noformat}
[number1] nohup: failed to run command `sh': No such file or directory
{noformat}

Commented is some troubleshoot steps.
Can be resolved by getting the container path into a file, pass it into a variable and finally pass that to withEnv.

Be aware that echo adds a new line to the file and in my case, this was also triggering the same issue. Use trim() to remove the extra line.
Use The use of printf instead of echo will avoid the trim() usage.

CentOS 7
Jenkins 2.46

{noformat}
{noformat}

alobato@cloudbees.com (JIRA)

unread,
Mar 5, 2017, 6:08:02 PM3/5/17
to jenkinsc...@googlegroups.com

I've done multiple tests and I can't reproduce this issue. Can you give me the exact versions of the pipeline plugins you are running? The easiest way to help me reproduce this is to install the Support Plugin and generate a support bundle which will contain all the envirornment information.

Did you check if this is related to JENKINS-41339?

This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

dantran@gmail.com (JIRA)

unread,
Mar 7, 2017, 3:59:04 PM3/7/17
to jenkinsc...@googlegroups.com
dan tran updated an issue
Change By: dan tran
Attachment: image-2017-03-07-12-58-37-245.png

dantran@gmail.com (JIRA)

unread,
Mar 7, 2017, 3:59:05 PM3/7/17
to jenkinsc...@googlegroups.com

dantran@gmail.com (JIRA)

unread,
Mar 7, 2017, 4:02:01 PM3/7/17
to jenkinsc...@googlegroups.com
dan tran commented on Bug JENKINS-40484
 
Re: Unable to use withMaven step inside docker container

here is my simple pipeline script running against 2.32.3. This time is has differente error ( nohub not found)
[pipeline-test] Running shell script
env: nohup: No such file or directory
 <code>

pipeline {

agent {
docker {
image "maven"
}
}

stages {

stage("run") {
steps {
withMaven( mavenSettingsConfig: 'maven-user', globalMavenSettingsConfig: 'maven-global', mavenLocalRepo: '.repository') {
sh "echo hello"

}
}
}

}

}

 

<code>

dantran@gmail.com (JIRA)

unread,
Mar 7, 2017, 4:04:02 PM3/7/17
to jenkinsc...@googlegroups.com
dan tran edited a comment on Bug JENKINS-40484
here is my simple pipeline script running against 2.32.3. This time is it has differente a different error ( nohub not found)  
[pipeline-test] Running shell script
env: nohup: No such file or directory


 <code>

pipeline \{

agent \{
docker \{
image "maven"
}
}

stages \{

stage("run") \{
steps \{
withMaven( mavenSettingsConfig: 'maven-user', globalMavenSettingsConfig: 'maven-global', mavenLocalRepo: '.repository') \{
sh "echo hello"

}
}
}

}

}

 

<code>

dantran@gmail.com (JIRA)

unread,
Mar 7, 2017, 4:05:03 PM3/7/17
to jenkinsc...@googlegroups.com
dan tran edited a comment on Bug JENKINS-40484
here is my simple pipeline script running against 2.32.3. This time it has a different error 

[pipeline-test] Running shell script
env: nohup: No such file or directory


  < \{ code > fomrat=xml}

pipeline \{

agent \{
docker \{
image "maven"
}
}

stages \{

stage("run") \{
steps \{
withMaven( mavenSettingsConfig: 'maven-user', globalMavenSettingsConfig: 'maven-global', mavenLocalRepo: '.repository') \{
sh "echo hello"

}
}
}

}

}

 
{code:java}
<  { code > }

dantran@gmail.com (JIRA)

unread,
Mar 7, 2017, 4:05:04 PM3/7/17
to jenkinsc...@googlegroups.com
dan tran edited a comment on Bug JENKINS-40484
here is my simple pipeline script running against 2.32.3. This time it has a different error 
[pipeline-test] Running shell script
env: nohup: No such file or directory

 \{code fomrat= : xml}


pipeline \{

agent \{
docker \{
image "maven"
}
}

stages \{

stage("run") \{
steps \{
withMaven( mavenSettingsConfig: 'maven-user', globalMavenSettingsConfig: 'maven-global', mavenLocalRepo: '.repository') \{
sh "echo hello"

}
}
}

}

}

 
{code:java}
 {code}

dantran@gmail.com (JIRA)

unread,
Mar 7, 2017, 4:06:01 PM3/7/17
to jenkinsc...@googlegroups.com
dan tran edited a comment on Bug JENKINS-40484
here is my simple pipeline script running against 2.32.3. This time it has a different error 
[pipeline-test] Running shell script
env: nohup: No such file or directory

 


\{code:xml}


pipeline \{

agent \{
docker \{
image "maven"
}
}

stages \{

stage("run") \{
steps \{
withMaven( mavenSettingsConfig: 'maven-user', globalMavenSettingsConfig: 'maven-global', mavenLocalRepo: '.repository') \{
sh "echo hello"

}
}
}

}

}

 
{code:java}
 {code}

dantran@gmail.com (JIRA)

unread,
Mar 7, 2017, 4:07:01 PM3/7/17
to jenkinsc...@googlegroups.com
dan tran edited a comment on Bug JENKINS-40484
here is my simple pipeline script running against 2.32.3. This time it has a different error 
[pipeline-test] Running shell script
env: nohup: No such file or directory

 

\{code
:xml }

pipeline \{

  agent \{
    docker \{
    image "maven"
    }
  }

  stages \{

    stage("run") \{
      steps \{
        withMaven( mavenSettingsConfig: 'maven-user', globalMavenSettingsConfig: 'maven-               global', mavenLocalRepo: '.repository') \{
            sh "echo hello"

          }
    }
  }

  }

  }

 
{code:java}
 {code}
Reply all
Reply to author
Forward
0 new messages