我必须根据项目 pqr 中的 xyz 管道是否成功或项目 pqr 中的管道 abc 是否成功来更新参数值。
那就是
pipeline successful parameter value
abc aaa
xyz zzz
我正在管道中尝试以下代码,但没有成功
Powershell:
if ('$(pqr.abc.result)' -eq 'succeeded') {
Write-Host "abc in pqr succeeded"
Write-Host "Setting component directory to aaa"
Write-Host "##vso[task.setvariable variable=component]$(Build.SourcesDirectory)\assets\aaa"
}
elseif ('$(pqr.xyz.result)' -eq 'succeeded')
{
Write-Host "xyz in pqr succeeded"
Write-Host "Setting component directory to zzz"
Write-Host "##vso[task.setvariable variable=component]$(Build.SourcesDirectory)\assets\zzz"
}
管道作为资源,只有运行成功才会触发当前管道。因此,无需在条件中使用资源管道的结果。您可以使用 管道资源变量
Resources.TriggeringAlias
根据触发管道的资源管道来设置 component
的值。请参阅下面的示例。
trigger:
- none
resources:
pipelines:
- pipeline: xyz # Name of the pipeline resource.
source: xyz # The name of the pipeline referenced by this pipeline resource.
project: pqr
trigger: true
- pipeline: abc # Name of the pipeline resource.
source: abc # The name of the pipeline referenced by this pipeline resource.
project: pqr
trigger: true
pool:
vmImage: windows-latest
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
if ('$(Resources.TriggeringAlias)' -eq 'abc') {
Write-Host "abc in pqr succeeded"
Write-Host "Setting component directory to aaa"
Write-Host "##vso[task.setvariable variable=component]$(Build.SourcesDirectory)\assets\aaa"
}
elseif ('$(Resources.TriggeringAlias)' -eq 'xyz')
{
Write-Host "xyz in pqr succeeded"
Write-Host "Setting component directory to zzz"
Write-Host "##vso[task.setvariable variable=component]$(Build.SourcesDirectory)\assets\zzz"
}