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:
#!/bin/bash echo "##vso[task.setvariable variable=testvar;]testvalue"
A useful example for this:
Let us say we use GitVersion to alleviate the headache of versioning and we put together a pipeline to publish a Nuget package.
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 inputs: command: pack packagesToPack: "$(project)" arguments: "--configuration $(buildConfiguration)" versioningScheme: byEnvVar versionEnvVar: THE_CORRECT_VERSION