Azure-pipelines-agent: YAML if conditions don't expand variables

Created on 26 Jul 2018  路  3Comments  路  Source: microsoft/azure-pipelines-agent

I have the following parameter in a yaml build and it's set to 'yes' in VSTS variables tab.

parameters:
  buildDebugPackage: '$(BuildDebugPackage)'

I would like to do the following

- ${{ if eq(parameters.buildDebugPackage, 'yes') }}:
  - ${{ parameters.preBuildDebugProjects }}
  - task: DotNetCoreCLI@2
    displayName: Build Debug Projects
    inputs:
      projects: ${{ parameters.projects }}
      arguments: '--no-restore -c Debug /p:Version=$(ASSEMBLY_VERSION);FileVersion=$(FILE_VERSION)'
  - ${{ parameters.postBuildDebugProjects }}

But this does not work because the variable BuildDebugPackage is not expanded to the value 'yes'.

I have to instead do the following

- powershell: |
    Write-Host "##vso[task.setvariable variable=BuildDebugPackage]$($env:BuildDebugPackage)"
  displayName: Setup Environment Variables
  env:
    BuildDebugPackage: ${{ parameters.buildDebugPackage }}
  ignoreLASTEXITCODE: false
  errorActionPreference: Stop
  failOnStderr: true

- ${{ parameters.preBuildDebugProjects }}
- task: DotNetCoreCLI@2
  displayName: Build Debug Projects
  condition: and(succeeded(), eq(variables[BuildDebugPackage], 'yes'))
  inputs:
    projects: ${{ parameters.projects }}
    arguments: '--no-restore -c Debug /p:Version=$(ASSEMBLY_VERSION);FileVersion=$(FILE_VERSION)'
- ${{ parameters.postBuildDebugProjects }}

This is far inferior as I cannot even condition the pre and post steps. This also shows up on the UI as a skipped step instead of not showing up at all. I also have to convert the parameter to a variable in PowerShell as well. Please fix this bug or give a workaround. Thanks.

enhancement

Most helpful comment

@vtbassmatt fyi - this is basically the process parameters for yaml feature on our backlog.

All 3 comments

@vtbassmatt fyi - this is basically the process parameters for yaml feature on our backlog.

We have created a new repository for all YAML related issues, please move the current issue to there.
https://github.com/Microsoft/azure-pipelines-yaml

@vtbassmatt fyi - here is a request for process parameters

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TLaborde picture TLaborde  路  3Comments

averelon picture averelon  路  3Comments

fernisoites picture fernisoites  路  4Comments

alexdegroot picture alexdegroot  路  5Comments

gitfool picture gitfool  路  4Comments