gpt4 book ai didi

Azure - 创建 bool 变量并在多个任务中使用它

转载 作者:行者123 更新时间:2023-12-03 00:47:08 25 4
gpt4 key购买 nike

我想为一个阶段定义一个 bool 变量,并希望在该阶段的任务之一的另一个脚本中设置它(True/False),并希望在其他后续任务中使用该变量作为条件,如何才能我做吗?

我的 Azure 管道基于 YAML。

最佳答案

I want to define one Boolean variable for a stage and want to set it(True/False) inside another script in one of the task in the stage and want to use that variable as a condition in other subsequent tasks, How can I do it?

这是一个例子:

stages:
- stage: Build
variables:
Key : false
jobs:
- job: Build
continueOnError: true
steps:
- script: echo Key:'$(Key)'

- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.

Write-Host "##vso[task.setvariable variable=Key;]true"

- task: CmdLine@2
inputs:
script: echo Key:'$(Key)'

- task: CmdLine@2
condition: and(succeeded(), eq(variables['Key'], 'true'))
inputs:
script: |
echo Write your commands here

echo Hello world

我有一个阶段变量Key,它的值为false。然后在 PS 任务中,我使用 task.setvariable 来覆盖键的值。 注意:这样新值true就是一个作业范围值。如果您在一个阶段有多个作业,则此方法效果不佳。

更新1:

- task: PowerShell@2
inputs:
filePath: 'Test.ps1'

我的测试.ps1:

Write-Host "##vso[task.setvariable variable=Key;]true"

关于Azure - 创建 bool 变量并在多个任务中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61093897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com