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.

  • Should I install Docker on Server Having Cpanel already on it?
  • Docker mount directory access rights
  • Clone a secure git repo in Kubernetes pod
  • Adding newuser in docker container with sudo privileges
  • How to deploy Spring Boot application to Google Managed VM
  • collecting reaction times from inside a 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.

  • Terminal with Docker Compose with Links
  • How to run same docker images twice
  • Docker multi-container logging cap
  • Docker Volume without linking. What is the use case?
  • docker container hostname sequential number
  • ERROR: compose.cli.main.main: 500 Internal Server Error: Cannot start container : [9] System error: not a directory
  • 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.