title: Maven tool is not set in Jenkins pipeline
body: <p>I have this stage in my Jenkins pipeline:</p>
  
  <pre><code>   stage('Build') {
         def mvnHome = tool 'M3'
         sh '''for f in i7j-*; do
                   (cd $f &amp;&amp; ${mvnHome}/bin/mvn clean package)
               done
               wait'''
     }
  </code></pre>
  
  <p>In <em>Jenkins » Manage Jenkins » Global Tool Configuration</em> I have a Maven installation called <code>M3</code>, version <code>3.3.9</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/LJdY9.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LJdY9.png" alt="Global Tool Configuration » Maven Installations"></a></p>
  
  <p>When running this pipeline, <code>mvnHome</code> is empty because I get this in the log:</p>
  
  <pre><code>+ /bin/mvn clean install -Dmaven.test.skip=true
  /var/lib/jenkins/jobs/***SNIP***/script.sh: 3: /var/lib/jenkins/jobs/***SNIP***/script.sh: /bin/mvn: not found
  </code></pre>
  
  <p>I did find a path <code>/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/M3</code> on the Jenkins server, which works, but I would prefer not to use a hard coded path to mvn in this script.</p>
  
  <p>How do I fix this?</p>
  
  <hr>
  
  <p><strong>EDIT</strong>: Summary of the <a href="https://stackoverflow.com/a/42693589/766786">answer</a>, using <code>tool</code> and <code>withEnv</code>.</p>
  
  <p>My working code is now:</p>
  
  <pre><code>   stage('Build') {
          def mvn_version = 'M3'
          withEnv( ["PATH+MAVEN=${tool mvn_version}/bin"] ) {
          sh '''for f in i7j-*; do
                  (cd $f &amp;&amp; mvn clean package -Dmaven.test.skip=true -Dadditionalparam=-Xdoclint:none  | tee ../jel-mvn-$f.log) &amp;
                done
                wait'''
          }
     }
  </code></pre>