如何使用参数在Azure DevOps中使用或任务条件

发布于 2025-01-17 22:38:38 字数 1252 浏览 1 评论 0原文

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') 

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

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) )

Added the complete code. Default value will be test111. Just need to verify the condition and execute the tasks.

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

Either of any one agent is matched, then condition should be allow to execute tasks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一片旧的回忆 2025-01-24 22:38:38

这种方法应该起作用。由于在编译时间之前填充了参数,因此您应该将此值分配给一个变量,以便在条件步骤上使用它。

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将运行。

This approach should work. As parameters are populated before the compile time, you should assign this value into a variable in order to use it on the condition step.

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') )

As the default value is evaluated correctly on the condition, the powershell will run.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文