Access SourceBranchName in Release pipeline

Viewed 1263

I'm trying to release my buildartifacts to a specific folder based on the name of the sourcebranch which upon creating a pull request triggered the build and therefor the release.

I've managed to so far to get:

write-host $env:RELEASE_TRIGGERINGARTIFACT_ALIAS
$triggerAlias = $env:RELEASE_TRIGGERINGARTIFACT_ALIAS

This alias (from my point of view) is the primary artifcat alias which I need to access

Release.Artifacts.{Primary artifact alias}.SourceBranchName

based on this documentation. So how do I combine the alias to get the sourcebranchname

$env:RELEASE_ARTIFACTS_{$triggerAlias}_SOURCEBRANCHNAME

This doesn't seem to be working and neither does

$env:RELEASE_ARTIFACTS_$($triggerAlias)_SOURCEBRANCHNAME

Any advice is much appreciated.

1 Answers

You can read the variable in this way:

$triggerAlias = $env:RELEASE_TRIGGERINGARTIFACT_ALIAS

$branchNameVariable = "RELEASE_ARTIFACTS_$($triggerAlias)_SOURCEBRANCHNAME"

#Get the value of the environment variable Release.Artifacts.{alias}.SourceBranchName
$branchName = (Get-item env:$branchNameVariable).Value
Related