'How to use OR task condition in azure devops using parameters
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | GeralexGR |

