Final Solution using ssh:
stage('Checkout') {
steps {
checkout scmGit(
branches: [[name: '${GERRIT_BRANCH}']],
extensions: [
cloneOption(
depth: 1,
shallow: true,
noTags: true,
),
[$class: 'UserIdentity', email: 'jenkins@x.internal', name: 'Jenkins']
],
userRemoteConfigs: [[
credentialsId: '<CRED_ID>',
refspec: '${GERRIT_REFSPEC}',
url: "ssh://jenkins@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
]]
)
script {
if (env.GERRIT_CHANGE_NUMBER && env.GERRIT_PATCHSET_NUMBER) {
def changeBranch = "change-${GERRIT_CHANGE_NUMBER}-${GERRIT_PATCHSET_NUMBER}"
sh "git checkout -b ${changeBranch} FETCH_HEAD"
sh "echo '============= Show Current Commit Log ============='"
sh "git log | cat"
}
}
}
}