azure - 如何使用参数在azure devops中使用OR任务条件

标签 azure azure-devops conditional-statements

parameters:
- name: agents
  displayName: Agent
  type: string
  default: test111
- name: tests
  displayName: “Hello test”
  type: string
  default:
    '"Hello World"'
- name: configuration_key
  displayName: Special Parameter Keyword
  type: string
  default: ""

jobs:
- job: tesst1
  strategy:
    matrix: ${{ parameters.execution_matrix }}
  variables:
    - name: 'TEST_S'
      value: ${{ parameters.tests }}
    - name: 'configuration_key'
      value: ${{ parameters.configuration_key }}
      displayName: App test
  timeoutInMinutes: 600
  pool:
    name: System_test
    
- task: DownloadPipelineArtifact@2
    inputs:
      source: 'specific'
      project: ‘Test APP’
      buildType: 'current'
      artifactName: ‘App Installer'
      pipeline: 001
      runVersion: 'latestFromBranch'
      runBranch: 'refs/heads/develop'
      targetPath: '$(Build.SourcesDirectory)/'
    displayName: 'Get Artifacts'
    condition: or( eq(‘{{parameters.agents}}', ‘test111’), eq(‘{{parameters.agents}}’, ‘test’222) )

添加了完整的代码。默认值为 test111。只需验证条件并执行任务即可。

  Note: If i use only one condition then its working like below.
  
  eq('$ {{parameters.agents}}', 'test111') 

任何一个代理匹配,则条件应允许执行任务。

最佳答案

这种方法应该有效。由于参数是在编译之前填充的,因此您应该将此值分配给变量,以便在条件步骤中使用它。

trigger:
- none

pr: none 

    parameters:
    - name: image
      displayName: Pool Image
      type: string
      default: ubuntu-latest
      values:
      - windows-latest
      - ubuntu-latest
      - macOS-latest
    
    pool:
      vmImage: ubuntu-latest
    
    variables:
    - name: myvar
      value: ${{ parameters.image}}
    steps:
    
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          # Write your PowerShell commands here.
          
          Write-Host "Hello World"
      condition: or( eq(variables.myvar, 'ubuntu-latest'), eq(variables.myvar, 'windows-latest') )

由于根据条件正确评估了默认值,powershell 将运行。

enter image description here

关于azure - 如何使用参数在azure devops中使用OR任务条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71676544/

相关文章:

ios - 错误: "Version could not be created from build. Please make sure that your .ipa file has the correct format"

r - 仅当列存在时才适用于数据框列表

HTML 电子邮件 : ! mso 条件技巧

azure-devops - 以编程方式访问 Azure Devops 中的管道变量组

c# - 将有条件构建的 SQL where 子句转换为 LINQ

c# - 通过 SSMS(sql server management studio)使用 Azure 本地开发存储

c# - Azure WebJob 计划错误 - 对象引用未设置为对象的实例

python - 如何在生成样本时阻止 Azure TTS 播放音频?

azure - Azure Functions 中具有多个输出的事务

azure-devops - 拉取请求的 Azure DevOps 批处理