在下面的代码中,我能够为两个存储库的(NCP001) 和 (NCP002) 集成持续集成,但我只想签出已收到最新提交更改的特定存储库以及自存储库$(Build.SourcesDirectory) 的 Azure .
下面的 yaml 文件已放置在单独的存储库中(即我的构建应用程序存储库)
Yaml 文件:
trigger:
- main
- feature
resources:
repositories:
- repository: NCP001_CVS1
type: git
name: SOA_TEST/NCP001_CVS1
ref: main
trigger:
- main
- repository: NCP002_CVS2
type: git
name: SOA_TEST/NCP002_CVS2
ref: main
trigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
- checkout: ??
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
请建议我如何实现此解决方案?
答案 0 :(得分:0)
如果我们在 Repo NCP001 中推送提交,它会触发构建管道,现在您只想 checkout NCP001 和 self repo,不要 checkout NCP002,对吗?
我们可以通过 REST API 和 condition
有一个字段 BUILD_SOURCEVERSION
,检查这个 doc
Build.SourceVersion
:此构建中包含的触发存储库的最新版本控制更改。在 Git 中,它是提交 ID。
我们可以添加power shell任务并调用REST API到list commit IDs,将最新的commit ID与变量Build.SourceVersion
进行比较,根据结果添加新的变量,然后使用{{中的条件1}} 步。
例如:
我的 repo 是 checkout
, 12
,self repo 是 test
YAML:
test repo
结果:
在 trigger:
- master
resources:
repositories:
- repository: 12
type: git
name: 12
trigger:
- master
- repository: test
type: git
name: test
trigger:
- master
steps:
- task: PowerShell@2
displayName: 'Pass Variable'
name: PassVariable
inputs:
targetType: 'inline'
script: |
$PAT="{pat token}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
#Get repo latest commit ID
$ListCommitURL = "https://dev.azure.com/{Org name}/{Project name}/_apis/git/repositories/{repo name, eg.test}/commits?api-version=6.0"
$ListCommit = Invoke-RestMethod -Uri $ListCommitURL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
Write-Host $ListCommit.value.commitId[0]
$CommitURL = "https://dev.azure.com/{Org name}/{project name}/_apis/git/repositories/{repo name, eg.12}/commits?api-version=6.0"
$Commit = Invoke-RestMethod -Uri $CommitURL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
Write-Host $Commit.value.commitId[0]
#Get repo latest commit ID with variable Build.SourceVersion
if($ListCommit.value.commitId[0] -eq '$(Build.SourceVersion)'){
Write-Host "##vso[task.setvariable variable=RepoName;isOutput=true]test"
}
if($Commit.value.commitId[0] -eq '$(Build.SourceVersion)'){
Write-Host "##vso[task.setvariable variable=RepoName;isOutput=true]12"
}
- checkout: self
- checkout: test
condition: eq(variables['PassVariable.RepoName'], 'test')
- checkout: 12
condition: eq(variables['PassVariable.RepoName'], '12')
存储库中推送提交
在 self
存储库中推送提交
在 test
存储库中推送提交
答案 1 :(得分:0)
这正是我要找的。非常感谢维托。你救了我一个大不了的:)
[1]:https://i.stack.imgur.com/LFZsO.png`Triggered 我的结果管道携带已提交的更改`[截图][1]