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

if I run my container like below everything works fine.

  • How to use gpicview inside docker?
  • How to edit a file dynamically in a running docker container
  • Adding tags to docker image from jenkins
  • Container spawning for interactive tutorial
  • Can Docker automatically add IP addresses to the host upon running container
  • Default elasticsearch configuration for docker container
  • 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.

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


    [Pipeline] {
    [Pipeline] stage (build and test)
    Entering stage build and test
    [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.

  • AWS ECS - Images from S3
  • Remote debugging running process inside docker container
  • Running Amazon-Linux Docker Image on MacOS
  • Prometheus Alert Rules with docker label only working with prefix “container_label_”?
  • How to avoid permission deny with uid/gid 1000 after mount volume with docker?
  • Unable to push a docker image to the docker hub
  • 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.