title: Howto: Insert a template conditionally in Azure DevOps YAML?
body: <p>Here's how I'm trying to accomplish inserting a template conditionally.  Per requirement, I would like to either call fresh-deploy.yml or update.yml based on a pipeline variable supplied at run time.  The user can edit a variable called 'freshInstall' to either true or false.</p>
  
  <p>The main pipeline (entrypoint):</p>
  
  <pre><code># azure-pipelines.yml
  variables:
    shouldUpdate: 'false'
  
  jobs:
    - job: TestJob
      pool:
        name: "Vyas' Local Machine"
      steps:
      - checkout: none
      - template: ./testIf.yml
        parameters:
          freshInstall: $(freshInstall)
  </code></pre>
  
  <p>The testif.yml:</p>
  
  <pre><code># testIf.yml
  parameters:
    - name: freshInstall
      type: string  # Can't be boolean as runtime supplied variable values ARE strings
  
  steps:
  
    # set a preexisting variable valued 'false' to 'true'
    - powershell: |
        $shouldUpdate = 'true'
        Write-Host "##vso[task.SetVariable variable=shouldUpdate]$shouldUpdate"
      displayName: 'Set Should Update to $(shouldUpdate)'
  
    # Check if the parameter 'freshInstall' is passed in correctly
    - script: echo "Should freshInstall ${{ parameters['freshInstall'] }}"
      displayName: 'Is Fresh Install? ${{ parameters.freshInstall }}'
  
    # Should skip this
    - ${{ if eq(parameters.freshInstall, 'true') }}:
      - template: ./fresh-deploy.yml
  
    # Shoud include this
    - ${{ if eq(parameters.freshInstall, 'false') }}:
      - template: ./update.yml
  
    # Check variables vs parameters.  Include as per value set
    - ${{ if eq(variables.shouldUpdate, 'true') }}:
      - template: ./update.yml
  
    # Use all 3 syntaxes of variable access
    - script: echo "shouldUpdate is variables['shouldUpdate']"
      displayName: "Should Update? variables.shouldUpdate"
  </code></pre>
  
  <p>The mock file for fresh-deploy.yml:</p>
  
  <pre><code># fresh-deploy.yml
  steps:
    script: echo 'Kick off fresh deploy!'
  </code></pre>
  
  <p>The mock file for update.yml:</p>
  
  <pre><code># update.yml
  steps:
    script: echo 'Updating existing installation!'
  </code></pre>
  
  <p>Critical issue: The expectation is that the update.yml template is inserted and the script run when the variable 'freshInstall' is false.</p>
  
  <p>Nice to know: I was also checking if I could somehow get this to work if it were a variable instead of a parameter. It'd be nice if I could be pointed to what I'm doing wrong with the variable displays.</p>
  
  <p>Here's the result:
  <a href="https://i.stack.imgur.com/YYLBu.png" rel="noreferrer"><img src="https://i.stack.imgur.com/YYLBu.png" alt="enter image description here"></a></p>