我正在嘗試在 AzureDevops 中創建一個管道,該管道將在創建拉取請求時運行。示例:主分支 test1 分支
當我創建拉取請求以將 test1 分支合并到主分支時,我的管道運行應自動更新 readme.md 檔案將其推回 test1 分支,這樣當拉取請求被批準時,我也將擁有最新的readme.md 檔案。
但我面臨以下問題:
On branch refs/heads/callerid
nothing to commit, working tree clean
To https://dev.azure.com/repository
! [rejected] refs/heads/callerid -> refs/heads/callerid (fetch first)
error: failed to push some refs to 'https://dev.azure.com/repository'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git config --global init.defaultbranch $(system.pullRequest.sourceBranch)
git add .
git commit -m "deployment $(Build.BuildNumber) [skip ci]"
git push --set-upstream origin $(system.pullRequest.sourceBranch)
有什么我應該在這里改變的嗎?基本上這就是我遇到問題的地方。
從存盤庫中洗掉了實際鏈接。
我想要一個沒有那個 refs/heads 的干凈的分支名稱。在上面的場景中,為將 callerid 分支合并到主分支而創建的拉取請求。并且呼叫者 ID 應該在 readme.md 上有最新更新,并且在這個管道中,然后 pr 的批準會將其合并到主分支
uj5u.com熱心網友回復:
請確保您已將專案集合構建服務(組織名稱){身份一}的“貢獻”權限設定為允許。如果您使用 yaml,請添加一個將 persistCredentials 設定為 true 的結帳部分。您可以查看檔案了解更多詳細資訊: https ://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/git-commands?view=azure-devops&tabs=yaml
然后我可以重現你的問題。我將專案集合構建服務(組織名稱){身份一}的“強制推送”權限設定為允許,這對我來說效果很好。這是代碼:
steps:
- checkout: self
fetchDepth: 1
persistCredentials: True
- task: PowerShell@2
displayName: PowerShell Script
inputs:
targetType: inline
script:
git config --global user.email "**@**.com"
git config --global user.name "**"
git checkout -b test1
Add-content -Path $(System.DefaultWorkingDirectory)/README.md -Value "'nss"(you could add the content you want after 'n')
git add .
git commit -m "**"
git branch --set-upstream-to=origin/test1 test1
git pull
git push --set-upstream origin test1 --force
displayName: 'PowerShell Script'
請看看它是否對您有用。謝謝。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/527923.html
