在Jenkins声明性管道中,带有选项{ skipDefaultCheckout() }
的方法是否可以获取Jenkins甚至在调用checkout scm
之前尝试签出的git commit?
我可以看到env变量:
BRANCH_NAME
但不提交
答案 0 :(得分:1)
您可以尝试以下操作:
repoUrl = 'ssh://git@repo.addr/repo.git'
node {
branchHash = sh(
script: "echo -n \$( git ls-remote ${repoUrl} refs/heads/${env.BRANCH_NAME} | cut -f1 )",
returnStdout: true
).trim()
}
pipeline {}