title: Jenkins Pipeline - How do I use the 'tool' option to specify a custom tool?
body: <p>I have a custom tool defined within Jenkins via the Custom Tools plugin. If I create a freestyle project the <code>Install custom tools</code> option correctly finds and uses the tool (Salesforce DX) during execution.</p>
  
  <p>However, I cannot find a way to do the same via a pipeline file. I have used the pipeline syntax snippet generator to get:</p>
  
  <pre><code>tool name: 'sfdx', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool'
  </code></pre>
  
  <p>I have put that into my stage definition:</p>
  
  <pre><code>stage('FetchMetadata') {
      print 'Collect Prod metadata via SFDX'
      tool name: 'sfdx', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool'
      sh('sfdx force:mdapi:retrieve -r metadata/ -u DevHub -k ./metadata/package.xml')
  }
  </code></pre>
  
  <p>but I get an error message stating <code>line 2: sfdx: command not found</code></p>
  
  <p>Is there some other way I should be using this snippet?</p>
  
  <p>Full Jenkinsfile for info:</p>
  
  <pre><code>node {
      currentBuild.result = 'SUCCESS'`
  
          try {
              stage('CheckoutRepo') {
                  print 'Get the latest code from the MASTER branch'
                  checkout scm
              }
  
              stage('FetchMetadata') {
                  print 'Collect Prod metadata via SFDX'
                  tool name: 'sfdx', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool'
                  sh('sfdx force:mdapi:retrieve -r metadata/ -u DevHub -k ./metadata/package.xml')
              }
  
              stage('ConvertMetadata') {
                  print 'Unzip retrieved metadata file'
                  sh('unzip unpackaged.zip .')
                  print 'Convert metadata to SFDX format'
                  sh('/usr/local/bin/sfdx force:mdapi:convert -r metadata/unpackaged/ -d force-app/')
              }
  
              stage('CommitChanges') {
                  sh('git add --all')
                  print 'Check if any changes need committing'
                  sh('if ! git diff-index --quiet HEAD --; then echo "changes found - pushing to repo"; git commit -m "Autocommit from Prod @ $(date +%H:%M:%S\' \'%d/%m/%Y)"; else echo "no changes found"; fi')
                  sshagent(['xxx-xxx-xxx-xxx']) {
                      sh('git push -u origin master')
                  }
              }
          }
          catch (err) {
              currentBuild.result = 'FAILURE'
              print 'Build failed'
              error(err)
          }
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>
  I have made some progress using <a href="https://github.com/dcarroll/sfdx-dreamhouse-dc/blob/master/Jenkinsfile" rel="noreferrer">this example Jenkinsfile</a>
  My stage now looks like this:</p>
  
  <pre><code>        stage('FetchMetadata') {
              print 'Collect Prod metadata via SFDX'
              def sfdxLoc =  tool 'sfdx'
              sh script: "cd topLevel; ${sfdxLoc}/sfdx force:mdapi:retrieve -r metadata/ -u DevHub -k ./metadata/package.xml"
          }
  </code></pre>
  
  <p>Unfortunately, although it looks like Jenkins is now finding and running the sfdx tool, I get a new error:</p>
  
  <pre><code>TypeError: Cannot read property 'run' of undefined
      at Object.&lt;anonymous&gt; (/var/lib/jenkins/.cache/sfdx/tmp/heroku-script-509584048:20:4)
      at Module._compile (module.js:570:32)
      at Object.Module._extensions..js (module.js:579:10)
      at Module.load (module.js:487:32)
      at tryModuleLoad (module.js:446:12)
      at Function.Module._load (module.js:438:3)
      at Module.runMain (module.js:604:10)
      at run (bootstrap_node.js:394:7)
      at startup (bootstrap_node.js:149:9)
      at bootstrap_node.js:509:3
  </code></pre>