![](/img/trans.png)
[英]git: need to build on one branch and merge that branch to another branch
[英]Jenkins with Git - Merge another branch *into* the current branch before build
我有一個jenkins CI設置,其中開發工作在功能分支中完成,當對master
分支進行拉取請求時,Jenkins針對該pull請求運行構建以確認所有測試都在通過。 然后將其同步回我們的倉庫,以便審查拉取請求的人知道測試沒有進行。
我想更新此設置,以便在Jenkins從pull請求構建分支之前,它將master
合並到 pull請求分支並構建結果。 不應該推回此合並,因為它仍處於等待審核狀態,但這將確保測試針對實際的拉取后請求結果運行。
我已經找到了信息,並Merge before build
操作Merge before build
嘗試了Merge before build
但這似乎將pull請求分支合並到master
,然后如果成功,請檢查pull request branch back out out build。 這是偉大的追趕未來合並conficts,但仍然沒有趕上拉請求分支與master
建築前。
在Git插件的文檔( https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin )中,它提到了一個看似完全符合我想要的功能:“接下來,選擇一個特定的分支名稱為“高級”部分中的集成目標 - (例如“master”或“stable”),並選擇“在構建前合並”,但在Jenkins中我無法使用此選項。 我有最新的插件,所以我不確定他們是否刪除了這個並沒有更新他們的文檔或什么。
有誰知道如何實現“將另一個分支合並到我當前的分支並構建結果”操作?
謝謝!
您應該使用SHA檢查PR Branch和master是否同步。 如果它們不同步,則在運行構建階段之前進行git rebase
。
stage ("Rebase Master") {
pr_branch_name = sh(script: "curl https://github.com/api/v3/repos/${git_org}/${git_repo}/pulls/${CHANGE_ID} -H \"Content-Type: application/json\" -H \"authorization: token ${authentication_token}\" | jq -r .head.ref", returnStdout: true).trim()
rebaseability = sh(script: "curl https://github.com/api/v3/repos/${git_org}/${git_repo}/pulls/${CHANGE_ID} -H \"Content-Type: application/json\" -H \"authorization: token ${authentication_token}\" | jq -r 'select(.base.sha==.head.sha) | \"up-to-date\"'", returnStdout: true).trim()
if (rebaseability != "up-to-date" ) {
git checkout ${pr_branch_name}
git rebase master
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.