【问题标题】:need to set condition from variables in azure pipelines需要从 azure 管道中的变量设置条件
【发布时间】:2021-02-02 12:56:57
【问题描述】:

我在全局级别设置变量,并在运行管道之前通过变量提供值,尝试使用变量设置条件但未能成功。下面是我的示例管道

  trigger
    - develop
  variables:
    stagename: $(stagename)

  stages:
  - stage: deploy
      - task: download artifact
        condition:  notin(variables($(stagename),(tst1,tst2)))

      - task: deploy2
        condition: notin(variables($(stagename),(tst1,tst2)))

如果 stagname 等于 tst1 或 tst2,目标是不运行在这两个任务之上,应该在其他情况下运行。

【问题讨论】:

    标签: azure-devops azure-pipelines


    【解决方案1】:

    您可以参考以下示例,它对我有用:

    trigger:
      - develop
    stages:
    - stage: deploy
      jobs:
      - job: Build
        steps:
        - task: PowerShell@2
          condition: notin(variables['stagename'],'tst1','tst2')
          inputs:
            targetType: 'inline'
            script: |
              Write-Host "Hello World"
    

    您不需要在管道根级别设置变量。在管道根级别设置的变量将覆盖在管道设置 UI 中设置的变量。这是关于define variablesspecify conditions 的文档。

    【讨论】:

      猜你喜欢
      • 2019-08-23
      • 2020-09-08
      • 2021-11-23
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 2020-11-03
      • 2020-09-20
      • 1970-01-01
      相关资源
      最近更新 更多