[英]How to get parent ID for a commit in a gerrit triggered jenkins pipeline job
In the pipeline code, I need to retrieve the parent ID for a commit in the jenkins pipeline job triggered by gerrit trigger. 在管道代码中,我需要检索由gerrit触发器触发的jenkins管道作业中的提交的父ID。
I tried to get the parent ID from the gerrit trigger environment variable $GERRIT_PATCHSET_REVISION 我试图从gerrit触发器环境变量$ GERRIT_PATCHSET_REVISION中获取父ID。
echo "$GERRIT_PATCHSET_REVISION^"
echo "${GERRIT_PATCHSET_REVISION}^"
echo "${env.GERRIT_PATCHSET_REVISION}^"
echo "$GERRIT_PATCHSET_REVISION^^"
echo "${GERRIT_PATCHSET_REVISION}^^"
echo "${env.GERRIT_PATCHSET_REVISION}^^"
Actual result: SHA1 value of current commit, GERRIT_PATCHSET_REVISION value followed by 1 or 2 carets ("^") 实际结果:当前提交的SHA1值,GERRIT_PATCHSET_REVISION值后跟1或2个脱字号(“ ^”)
Expected result: SHA1 value of parent commit 预期结果:父提交的SHA1值
Jenkins is unable to interpret and escape "^". Jenkins无法解释和转义“ ^”。 Any pointers would be of great help!
任何指针都会有很大帮助!
Use git rev-parse
instead of echo
, supposing in bash: 假设在bash中使用
git rev-parse
而不是echo
:
firstparent=$(git rev-parse ${GERRIT_PATCHSET_REVISION}^)
echo ${firstparent}
To successfully retrieve the parent commit, the commit object of the patchset revision must be available from a local git repository. 要成功检索父提交,补丁集修订的提交对象必须可从本地git存储库中获得。 If the snippet runs outside the repository, use
git --git-dir=<path_to_repo_.git> rev-parse ${GERRIT_PATCHSET_REVISION}^
. 如果代码段在存储库外部运行,请使用
git --git-dir=<path_to_repo_.git> rev-parse ${GERRIT_PATCHSET_REVISION}^
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.