Issue
I would like to checkout code at a given commit in a Pipeline but the git
step only allows to use a branch.
Environment
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
-
CloudBees CI (CloudBees Core) on traditional platforms - Client controller
-
CloudBees Jenkins Enterprise - Managed controller
Resolution
You can accomplish this using the generic scm step.
This steps is much more verbose that the git
step but it provides access to most of the parameters of the git plugin.
The easiest way to configure it is to use the Pipeline Snippet Generator. Please refer to Pipeline: Best Practices if you are unsure how to access the Snippet Generator.
Here is a simple example that will checkout from gitUrl
at commit commitId
:
node { checkout([ $class: 'GitSCM', branches: [[name: ${commitId}]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: ${gitUrl}]]]) sh 'ls -al' }