Wrestled this awhile myself. Used the following function instead since I checkout to a local branch:
private String getRealLastCommit(branch_name){ def lastCommit="" if(steps.isUnix()){ lastCommit = steps.sh([script: "git log -1 --pretty=format:\"%H\" origin/${branch_name}", returnStdout: true]).trim() } else{ lastCommit = steps.bat([script: "git log -1 --format=\"%%H\" origin/${branch_name}", returnStdout: true]).split( '\n' )[2].trim() } steps.echo("DEBUG Last Commit ID:${lastCommit}") return lastCommit }