title: Jenkins pipeline mvn: command not found
body: <p>My test is working fine as Maven project. It fetches code from Git.</p>
  
  <p>I wanted to execute the same in Pipeline so I wrote the below script for pipeline project.</p>
  
  <pre><code>pipeline {
      agent any
      options {
          timestamps()
      }
      stages{ 
          stage('Just Testing') {
              steps {
                  git "https://github.com/myRepo.git"
                  script{
                          sh 'mvn test'
                  }
                  step([$class : 'Publisher', reportFilenamePattern : "**/testng-results.xml"])
              }
          }
      }   
  }
  </code></pre>
  
  <p>But when I execute I am getting mvn: command not found error Java and Maven path is set correctly in global tool configuration (I am sure because I am able to execute other maven projects, only pipeline is failing.)</p>
  
  <p>Console output:</p>
  
  <pre><code>Running on Jenkins in /Users/abacker/.jenkins/workspace/parallelTestNG
  [Pipeline] {
  [Pipeline] timestamps
  [Pipeline] {
  [Pipeline] stage
  [Pipeline] { (Just Testing)
  [Pipeline] git
  00:03:52  No credentials specified
  00:03:52   &gt; git rev-parse --is-inside-work-tree # timeout=10
  00:03:52  Fetching changes from the remote Git repository
  00:03:52   &gt; git config remote.origin.url https://github.com/myRepo.git # timeout=10
  00:03:52  Fetching upstream changes from https://github.com/myRepo.git
  00:03:52   &gt; git --version # timeout=10
  00:03:52   &gt; git fetch --tags --force --progress -- https://github.com/myRepo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
  00:03:54   &gt; git rev-parse refs/remotes/origin/master^{commit} # timeout=10
  00:03:54   &gt; git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
  00:03:54  Checking out Revision e82f48106aa72d0275591926d9cd3226ba0fefd7 (refs/remotes/origin/master)
  00:03:54   &gt; git config core.sparsecheckout # timeout=10
  00:03:54   &gt; git checkout -f e82f48106aa72d0275591926d9cd3226ba0fefd7 # timeout=10
  00:03:54   &gt; git branch -a -v --no-abbrev # timeout=10
  00:03:54   &gt; git branch -D master # timeout=10
  00:03:54   &gt; git checkout -b master e82f48106aa72d0275591926d9cd3226ba0fefd7 # timeout=10
  00:03:54  Commit message: "First commit"
  00:03:54   &gt; git rev-list --no-walk e82f48106aa72d0275591926d9cd3226ba0fefd7 # timeout=10
  [Pipeline] script
  [Pipeline] {
  [Pipeline] sh
  00:03:54  + mvn test
  00:03:54  /Users/abacker/.jenkins/workspace/parallelTestNG@tmp/durable-818e64a8/script.sh: line 1: mvn: command not found
  [Pipeline] }
  [Pipeline] // script
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] }
  [Pipeline] // timestamps
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  ERROR: script returned exit code 127
  Finished: FAILURE
  </code></pre>
  
  <p>How can I fix this issue?</p>