Search code examples
azure-devopsazure-pipelinescicd

How can I use 'or' condition in variables block in AzureDevops?


I'm trying to set the value of a var1 if mode is not dev or variable var2 has the value true

  - name: var1
    value: $[or(eq(variables['var2'], true), ne(variables['Mode'], 'dev'))]

But when I run the pipeline, I see that the variable takes the value false

  var2:
    Parsing expression: <or(eq(variables['var2'], true), ne(variables['Mode'], 'dev'))>
    Evaluating: or(eq(variables['var2'], True), ne(variables['Mode'], 'dev'))
    Expanded: or(eq('$[or(eq(variables[''var2''], true), ne(variables[''Mode''], ''dev''))]', True), ne('dev', 'dev'))
    Result: 'False'

What I did wrong?


Solution

  • I tested this:

    variables:
    - group: Some-secrets
    - name: Mode
      value: prod
    - name: var2
      value: true
    - name: var1
      value: $[or(eq(variables['var2'], true), ne(variables['Mode'], 'dev'))]
    
    
    pool:
      vmImage: ubuntu-latest
    
    steps:
    - script: env | sort
      displayName: 'Display env variables'
    
    - script: |
        echo "$(var1)"
        echo "$(var2)"
    

    and it was evaluated properly:

      var1:
        Parsing expression: <or(eq(variables['var2'], true), ne(variables['Mode'], 'dev'))>
        Evaluating: or(eq(variables['var2'], True), ne(variables['Mode'], 'dev'))
        Expanded: or(eq('true', True), ne(variables['Mode'], 'dev'))
        Result: 'True'
    

    Could you share you full pipeline?