Mike Christensen
Mike Christensen

Reputation: 91628

How to create conditional build properties in DevOps build pipeline

I have the following build pipeline task:

  - task: NuGetCommand@2
    displayName: 'Pack CodingStyles.nuspec'
    inputs:
      command: 'pack'
      packagesToPack: 'src\CodingStyles\CodingStyles.nuspec'
      packDestination: 'src\CodingStyles\bin'
      versioningScheme: 'off'
      buildProperties: '-NoDefaultExcludes -Version $(Build_Major).$(Build_Minor).$(Build_Patch)'

However, if the variable $IsPreRelease is true, I want to add another build property as well:

buildProperties: '-NoDefaultExcludes -Version $(Build_Major).$(Build_Minor).$(Build_Patch) -Suffix beta'

A few thoughts on how to do this:

  1. I could have two different versions of this task, each with a condition: based on the variable. This would probably work, but it's quite redundant since everything else is the same.
  2. Run a Powershell task instead of the NuGetCommand task, and build my command line dynamically.

Any options I'm missing?

Upvotes: 0

Views: 1101

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40653

You are missing one option:

  - task: NuGetCommand@2
    displayName: 'Pack CodingStyles.nuspec'
    inputs:
      command: 'pack'
      packagesToPack: 'src\CodingStyles\CodingStyles.nuspec'
      packDestination: 'src\CodingStyles\bin'
      versioningScheme: 'off'
      ${{ if ne(variables['IsPreRelease'], 'true') }}:
        buildProperties: '-NoDefaultExcludes -Version $(Build_Major).$(Build_Minor).$(Build_Patch)'
      ${{ if eq(variables['IsPreRelease'], 'true') }}:
        buildProperties: '-NoDefaultExcludes -Version $(Build_Major).$(Build_Minor).$(Build_Patch) -Suffix beta'

enter image description here

Upvotes: 2

Related Questions