The mind is like a parachute. If it doesn't open, you're meat.

ForgetMeNot: Pass values onwards in Azure Devops

27 Jan 2020

Azure Devops has this really cool feature, where you can use specially formated stdout strings to pass different commands.

They are called logging commands and by far the most useful of those is setvariable which allows us to set a variable in one task, that is then available as an environment variable in subsequent tasks:

echo "##vso[task.setvariable variable=testvar;]testvalue"

A useful example for this:

Let us say we use GitVersion to aleviate the headache of versioning and we put together a pipeline to publish a Nuget package.

The dotnet task in Azure Devops (as well as the nuget task) offers the byEnvVAr versioning scheme, which allows you to pass the desired version number in an environment variable.

Use you favourite scripting language to calculate the version number and a logging command, for example with bash

- script: echo "##vso[task.setvariable variable=THE_CORRECT_VERSION;]`GitVersion /output json /showvariable FullSemVer`"

and then pack the Nuget package without worrying about the version:

- task: DotNetCoreCLI@2
    command: pack
    packagesToPack: "$(project)"
    arguments: "--configuration $(buildConfiguration)"
    versioningScheme: byEnvVar
    versionEnvVar: THE_CORRECT_VERSION

blog comments powered by Disqus