title: How to mount Jenkins workspace in docker container using Jenkins pipeline
body: <p>I'm using Jenkins in docker. The <code>/var/jenkins_home</code> is mounted on <code>/var/jenkins-data</code> on my host. My Jenkins can execute docker commands (mount of sockets) and I've installed the git plugin and pipeline plugin.</p>
  
  <p>Now I have a pipeline job named <code>test</code> and the following pipeline:</p>
  
  <pre><code>pipeline {
      agent any
      stages {
          stage('Clone') {
              steps {
                  git branch: 'master', url: 'https://github.com/lvthillo/maven-hello-world.git'
              }
          }
  
          stage('Build in Docker') {
              agent {
                  docker {
                      image 'maven:3.5.2'
                      args '-v /var/jenkins_home/workspace/test:/opt/maven -w /opt/maven'
                  }
              }
  
              steps {
                  sh 'pwd'
                  sh 'mvn -v'
                  sh 'mvn clean install'
              }
          }
      }
  }
  </code></pre>
  
  <p>What I want to achieve is cloning my public repo from github. This works. In the next step I want to start a docker container (maven) and print the current directory, the maven version and perform a clean install.</p>
  
  <p>The output of the 3 commands is:</p>
  
  <pre><code>[test@2] Running shell script
  + pwd
  /var/jenkins_home/workspace/test@2
  [Pipeline] sh
  [test@2] Running shell script
  + mvn -v
  Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)
  Maven home: /usr/share/maven
  Java version: 1.8.0_151, vendor: Oracle Corporation
  Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
  Default locale: en, platform encoding: UTF-8
  OS name: "linux", version: "4.4.86-boot2docker", arch: "amd64", family: "unix"
  [Pipeline] sh
  [test@2] Running shell script
  + mvn clean install
  
  [INFO] Scanning for projects...
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 0.179 s
  [INFO] Finished at: 2018-01-12T12:12:00Z
  [INFO] Final Memory: 5M/31M
  [INFO] ------------------------------------------------------------------------
  [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/var/jenkins_home/workspace/test@2). Please verify you invoked Maven from the correct directory. -&gt; [Help 1]
  </code></pre>
  
  <p>It seems to work because maven is not installed on my host, so it's executed from inside the container, but it's suddenly creating a new workspace (<code>@2</code>) instead of using the existing one from where I cloned the repo. I don't want to clone the repo in my container immediately because I want multiple stages, all with different containers, but all executed on my git repo in my workspace.</p>
  
  <p>What am I doing wrong or how can I fix this?
  I was thinking it was maybe because of the agent step. my first step can run on any agent (any slave), the docker step will run in the docker container, but must of course run on that same slave als where the <code>git clone</code> was executed.</p>