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.

  • Connect many Jenkins servers with different branches of the same github repo
  • How to connect to MongoDB running in Docker container?
  • “Dockerized” apps frequently are built on top of OS containers. Why doesn't this defeat the purpose?
  • docker swarm http connectivity
  • Logging in ASP.NET application runnin in Docker container
  • Using Jenkins - Build Enviroment
  • 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.

  • How to run HDFS cluster without DNS
  • Access NFS files from Docker
  • docker error: /var/run/docker.sock: no such file or directory
  • Docker image creation exception: “This archives contains unclosed entries”
  • Docker Mac Beta using insecure Private Registry
  • Docker CLI in Freestyle Build Shell
  • 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.