![](/img/trans.png)
[英]How to discover azure devops pull requests in jenkins Multibranch Pipeline
[英]Azure Devops pipeline - is it possible to checkout to pull requests?
我希望在每個 PR 上測試代碼,然后再進入主分支。
我知道我可以在主分支上進行構建驗證,這將導致管道在每個 PR 上運行。
但這需要為每個回購建立一個單獨的管道,我有大約 50..
我想要一個管道來檢查 PR 上的代碼。 我知道我可以觸發不同回購/項目上的管道,但我如何對 PR 進行“結帳”? 我不想檢出到源分支或目標分支,我想在合並之后但在進入主分支之前檢出 PR 上的代碼。
謝謝你。
拉取請求觸發器確實與一個存儲庫相關聯。
您可以在指定多個存儲庫時嘗試測試該觸發器(同樣,用於測試)
resources:
repositories:
- repository: MyGitHubRepo # The name used to reference this repository in the checkout step
type: github
endpoint: MyGitHubServiceConnection
name: MyGitHubOrgOrUser/MyGitHubRepo
- repository: MyBitbucketRepo
type: bitbucket
endpoint: MyBitbucketServiceConnection
name: MyBitbucketOrgOrUser/MyBitbucketRepo
trigger:
- ...
這將是一種解決方法,因為這意味着手動管理存儲庫列表。
根據您的要求,您需要為所有回購設置一個管道以簽出合並請求分支。
恐怕沒有開箱即用的方法可以直接滿足您的要求。
作為解決方法,您可以使用 Pull Request Related Pipeline 變量和 git 命令來檢查相關的 pull request 代碼。
當您為主分支設置構建驗證時,管道將是 PR 觸發器。 它將生成管道變量: $(System.PullRequest.SourceRepositoryURI)和$(BUILD.SOURCEVERSION) 。 它們包含 Pull Request Repo URL 和 Pull Request 分支。
更詳細的信息可以參考文檔: 預定義變量。
這是一個例子:
jobs:
- job: Variables
displayName: 'Variables'
steps:
- checkout: none
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$PullRequestURL = "$(System.PullRequest.SourceRepositoryURI)"
$NewPullRequestURL= "$PullRequestURL.replace('AzureTest23@','$(system.accesstoken)@')"
git remote set-url origin $NewPullRequestURL
git fetch --force --tags --prune --prune-tags --progress --no-recurse-submodules origin --depth=1 +$(BUILD.SOURCEVERSION)
在這種情況下,管道將根據 Pull Request 信息克隆 repo。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.