Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps pipeline variables in .nuspec files

Is it possible to use Azure DevOps pipeline variables in .nuspec files, which are used for packages creation?

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>MyTemplate</id>
    <version>$(var1).$(var2).$(var3)</version>
    <description>
      Some template
    </description>
    <authors>Test Test</authors>
    <packageTypes>
      <packageType name="Template" />
    </packageTypes>
  </metadata>
</package>

Or is it a way to ovveride version specified in .nuspec file(it is required element) by those one in .yaml task?

task: NuGetCommand@2
  displayName: Pack template
  inputs:
    command: pack
    packagesToPack: '**/Template/*.nuspec'
    packDestination: $(Build.ArtifactStagingDirectory)
    versioningScheme: byPrereleaseNumber
    majorVersion: '$(var1)'
    minorVersion: '$(var2)'
    patchVersion: '$(var3)'

But with versioningScheme: byPrereleaseNumber we will get timestamp added to our numbers.

like image 874
user3132547 Avatar asked Nov 28 '18 16:11

user3132547


People also ask

How do I export a pipeline variable in Azure DevOps?

To import a build definition, choose +Import from the Build Definitions page, and select the . json file saved from the previous step. Navigate to the pipeline details page for your pipeline. Choose ... and select Export.

How do you pass variables in Azure Pipelines Yml tasks?

Passing variables between tasks in the same jobSet the value with the command echo "##vso[task. setvariable variable=FOO]some value" In subsequent tasks, you can use the $(FOO) syntax to have Azure Pipelines replace the variable with some value.

How do I use library variables in Azure pipeline?

To use a variable group, open your pipeline. Select Variables > Variable groups, and then choose Link variable group. In a build pipeline, you see a list of available groups. In a release pipeline, for example, you also see a drop-down list of stages in the pipeline.


1 Answers

Pop-up ToolTip for Build Properties:

Specifies a list of token=value pairs, separated by semicolons, where each occurrence of $token$ in the .nuspec file will be replaced with the given value. Values can be strings in quotation marks.

I figured out the following YAML by going into the UI builder for editing the pipeline visually, there's an "Advanced" pane inside the NuGet > Pack task. It allows you to specify additional token replacement values under "build properties" (buildProperties)

I have a feeling it's one of those things where you have to transform one type of token into another.. see the buildProperties on the last line:

variables:
  Parameters.requestedMajorVersion: '1'
  Parameters.requestedMinorVersion: '0'
  Parameters.requestedPatchVersion: '6'

steps:
- task: NuGetCommand@2
  displayName: 'NuGet pack'
  inputs:
    command: pack
    packagesToPack: '**/*.nuspec'
    versioningScheme: byPrereleaseNumber
    majorVersion: '$(Parameters.requestedMajorVersion)'
    minorVersion: '$(Parameters.requestedMinorVersion)'
    patchVersion: '$(Parameters.requestedPatchVersion)'
    includeSymbols: true
    buildProperties: 'id=$(Build.Variable)'

Example .nuspec

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata minClientVersion="2.5">
    <id>$id$</id>
like image 176
bkwdesign Avatar answered Oct 22 '22 11:10

bkwdesign