title: Jenkins pipeline: checkout explicit git commit
body: <p>I want to be able to say something like:</p>
  
  <pre><code>git branch: commitHash, credentialsId: credentialsId, url: url
  </code></pre>
  
  <p>The usecase: I'm doing parallel build and test runs on different platforms, and want to ensure each gets the same code. It is C++, and we build on separate platforms as well as building on them.</p>
  
  <p>If I do the above, it fails - the underlying code assumes the given branch actually is a branch, or you get something like:</p>
  
  <pre><code>[Linux64 Build]  &gt; git rev-parse origin/e4b6c976a0a986c348a211579f1e8fd32cf29567^{commit} # timeout=10
  [Pipeline] [Linux64 Build] }
  [Pipeline] [Linux64 Build] // dir
  [Pipeline] [Linux64 Build] }
  [Pipeline] [Linux64 Build] // node
  [Pipeline] [Linux64 Build] }
  [Linux64 Build] Failed in branch Linux64 Build
  </code></pre>
  
  <p>I've seen variations on this question asked before, although no actual answers - just suggestions like to stash the source code instead, etc. Not really what I'm after.</p>
  
  <p>The documentation suggests it ought to be possible to give explicit commit hashes, possibly using branches instead, but I can't work out the syntax and can't find any examples. When I do it, I get the master branch, I think - in our setup, master does not work.</p>
  
  <p>So far, the only solution I've found has been to checkout the branch and then explicitly call git to get the commit:</p>
  
  <pre><code>                git branch: branch, credentialsId: credentialsId, url: url
                  sh 'git checkout ' + commitHash
  </code></pre>
  
  <p>(where branch is the branch I originally got the hash for at the top of the job. It works but is not the neatest.</p>
  
  <p>Anybody got a better way?</p>