Issue with Jenkins pipeline script and docker maven image

I try to build my project inside of a docker container, the image looks like this:

FROM maven:3.3.9-jdk-8
WORKDIR mvnBuildDir
ENTRYPOINT ["mvn"]

if I run my container like below everything works fine.

  • Passing sensitive information to Docker container in AWS EC2 container service
  • Get IP address of host where docker engine is running
  • Symfony server:run in php Docker container
  • docker - cannot find aws credentials in container although they exist
  • Docker: cant send data from logstash container to Kafka container
  • How do I expose port from Container to host?
  • docker run -v /home/user/Worspace/myMavenProject:/mvnBuildDir myMaven3 clean package
    

    But if I try this in my Jenkinsfile I got an error which is telling me nothing.
    Jenkinsfile:

    //...
    def maven = docker.image("myMaven3");
    maven.inside("-v ${workdir}:/mvnBuildDir"){
        stage "build and test"
        sh "mvn clean install"
    }
    //..
    

    Error:

    [Pipeline] {
    [Pipeline] stage (build and test)
    Entering stage build and test
    Proceeding
    [Pipeline] sh
    [master] Running shell script
    + mvn clean install -s mvnSettings.xml
    [Pipeline] }
    $ docker stop 1fc920c00b46a1038b0f39e2adc6e67f702d48ccf10d3e0bb3514d1cee3a795b
    $ docker rm -f 1fc920c00b46a1038b0f39e2adc6e67f702d48ccf10d3e0bb3514d1cee3a795b
    [Pipeline] // withDockerContainer
    [Pipeline] }
    [Pipeline] // withDockerRegistry
    [Pipeline] }
    [Pipeline] // withEnv
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    ERROR: script returned exit code -1
    Finished: FAILURE
    

    Has anybody have an idea what the problem is here or has anybody another solution how to build my project inside the docker container?
    My whole workspace is mapped inside the container, so the problem isn’t that pom or something else is not found I think. If I run ‘mvn –version’ I got the right output.
    Thanks so far.

  • Meteor packages.json error workaround when upgrading from 1.2 to 1.3 and deploying in a docker container
  • Configuring Django with Nginx, uWSGI and Postgres on Docker
  • Increase HDFS configured capacity inside Docker
  • Docker - Ubuntu - bash: ping: command not found
  • Populate cassandra after Docker-compose finishes
  • Xdebug time out while running debug session (PhpFarm | phpFcgi)
  • One Solution collect form web for “Issue with Jenkins pipeline script and docker maven image”

    When using docker images I had the behavior that the command ended but the docker was still running, so I had no output.

    You could try ton invoke the docker via shell.

    sh 'docker pull myMaven3'

    sh 'docker run --rm -v ${workdir}:/mvnBuildDir myMaven3 clean install'

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.