如何在未来的任务条件中引用 powershell 脚本的输出变量?

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

我正在 Powershell 中的作业步骤中设置变量:

  - pwsh: ./myFile.ps1 
  name: myTaskName

  # Inside myFile.ps1
  Write-Host "##vso[task.setvariable variable=buildScope;isOutput=true]public"

我可以稍后在 YAML 中使用以下命令访问此内容:

- script echo $(myTaskName.buildScope)

...但我似乎无法在同一工作的未来步骤中使用它。我该怎么做?

到目前为止我最好的尝试是......

- task: DoSomething
condition: eq(variables.myTaskName.buildScope, 'public')

有什么问题?

提前致谢

azure-powershell azure-pipelines-yaml
1个回答
0
投票

如何在未来的任务条件中引用 powershell 脚本的输出变量?

您可以使用以下 yaml 脚本来完成此操作:

jobs:
- job: Rithwik_Job1
  displayName: 'Rithwik_Job1'
  steps:
  - pwsh: ./rith.ps1 
    name: rithtask

- job: Rithwik_Job2
  displayName: 'Rithwik_Job2'
  dependsOn: Rithwik_Job1
  condition: eq(dependencies.Rithwik_Job1.outputs['rithtask.buildScope'], 'public')
  steps:
  - script: echo "Hello Rithwik your testScope is public"

rith.ps1:

enter image description here

Output:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.