当另一个项目中的Azure管道成功时如何更新参数值

问题描述 投票:0回答:1

我必须根据项目 pqr 中的 xyz 管道是否成功或项目 pqr 中的管道 abc 是否成功来更新参数值。

那就是

pipeline successful   parameter value
    abc                aaa
    xyz                zzz

我正在管道中尝试以下代码,但没有成功

定义参数参数:

  • 名称:纽瑞尔 显示名称:“发布版本(semver)” 类型:字符串
  • 名称:组件 displayName: "组件目录" 类型:字符串 默认值:'$(Build.SourcesDirectory) ssets bc' 资源: 管道:
    • 管道:A_Pipeline 资料来源:美国广播公司 项目:pqr 扳机: 分支机构: 包括: - '*'
      • 管道:B_管道 来源:xyz 项目:pqr 扳机: 分支机构: 包括:- '*'

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"
}
powershell azure-devops azure-pipelines
1个回答
0
投票

管道作为资源,只有运行成功才会触发当前管道。因此,无需在条件中使用资源管道的结果。您可以使用 管道资源变量

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"
      }
© www.soinside.com 2019 - 2024. All rights reserved.