簡體   English   中英

從我剛剛在 Jenkins 作業中推送的提交中獲取更改 ID?

[英]Get change id from the commit i just pushed in a Jenkins job?

我需要從提交中從 gerrit 獲取更改 ID,我使用以下代碼推送同一個作業

git status
git add -A
git commit -m "Jenkins passed job commit"
git push origin HEAD:refs/for/branch_name/Topic_name

原因是我還需要提供評論 +1 label,我想對於 ssh api 呼叫我需要更改號碼。 也歡迎其他解決方案,它將為特定提交設置評論 label!

謝謝!

當您執行“git push”命令時,您會收到類似於以下 output 的內容:

remote: Processing changes: refs: 1, new: 1, done            
remote: 
remote: SUCCESS        
remote: 
remote:   https://GERRIT-SERVER/c/sandbox/helloworld/+/72712 Do a generic change [NEW]        
remote: 
To https://GERRIT-SERVER/a/sandbox/helloworld
 * [new branch]      HEAD -> refs/for/master

您可以將此 output 重定向到執行以下文件的文件:

git push origin HEAD:refs/for/master 2>&1 | tee output.log

然后您可以使用以下命令獲取 Change-Id:

if grep -q "SUCCESS" output.log
then
    changeid=$(grep "remote:" output.log | grep "GERRIT-SERVER" | cut -d "+" -f 2 | cut -d "/" -f 2 | cut -d " " -f 1)
fi

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM