'Azure Devops - Set Variable by Expression
I'm trying to create a counter expression based on the seed of our current version number, in order to output a beta pre-release build number.
e.g.
4.3.2.16-beta.1
4.3.2.16-beta.2
4.3.2.16-beta.3
and so on
I have variables defined as
Version.Major = 4
Version.Minor = 3
Version.Build = 2
Version.Revision = 16
I'm trying to set the counter variable in power shell once we have got the version number
But its not evaluating the expression? Each time I run the pipeline, the variable Version.Counter stays set at '0' which was the default value set when adding the variable to the pipeline.
Write-Host ("##vso[task.setvariable variable=Version.Counter;] $[counter(format('{0}.{1}.{2}.{3}', variables['Version.Major'], variables['Version.Minor'], variables['Version.Build'], variables['Version.Revision']), 1) ]")
This is the debug output from the powershell script in the pipeline
##[debug]
##[debug]$versionsArray = $tag.split('.')
##[debug]
##[debug]$major = $versionsArray[0]
##[debug]$minor = $versionsArray[1]
##[debug]$build = $versionsArray[2]
##[debug]$revision = $versionsArray[3]
##[debug]
##[debug]$revision = [int]$revision + 1 # set revision number to the next number - so it appears as the highest version.
##[debug]
##[debug]Write-Host ("##vso[task.setvariable variable=Version.Major;]$major")
##[debug]Write-Host ("##vso[task.setvariable variable=Version.Minor;]$minor")
##[debug]Write-Host ("##vso[task.setvariable variable=Version.Build;]$build")
##[debug]Write-Host ("##vso[task.setvariable variable=Version.Revision;]$revision")
##[debug]
##[debug]Write-Host ("##vso[task.setvariable variable=Version.Counter;] $[counter(format('{0}.{1}.{2}.{3}', variables['Version.Major'], variables['Version.Minor'], variables['Version.Build'], variables['Version.Revision']), 1) ]")
##[debug]
##[debug]$rev = 0
##[debug]$version = "$major.$minor.$build.$revision-beta.$rev";
##[debug]Write-Output $version
##[debug]
##[debug]Write-Host ("##vso[build.updatebuildnumber]$version")
##[debug]Write-Host ("##vso[task.setvariable variable=ReleaseVersion;]$version")'
##[debug]Env:INPUT_SCRIPTARGUMENTS (empty)
& 'C:\Users\Brendan\AppData\Local\Temp\tmpA922.ps1'
##[debug]Processed: ##vso[task.setvariable variable=Version.Major;]4
##[debug]Processed: ##vso[task.setvariable variable=Version.Minor;]3
##[debug]Processed: ##vso[task.setvariable variable=Version.Build;]2
##[debug]Processed: ##vso[task.setvariable variable=Version.Revision;]16
##[debug]Processed: ##vso[task.setvariable variable=Version.Counter;] $[counter(format('{0}.{1}.{2}.{3}', variables['Version.Major'], variables['Version.Minor'], variables['Version.Build'], variables['Version.Revision']), 1) ]
4.3.2.16-beta.0
##[debug]Update build number for build: 2055 to: 4.3.2.16-beta.0 at backend.
##[debug]Processed: ##vso[build.updatebuildnumber]4.3.2.16-beta.0
##[debug]Processed: ##vso[task.setvariable variable=ReleaseVersion;]4.3.2.16-beta.0
Async Command Start: Update Build Number
Update build number to 4.3.2.16-beta.0 for build 2055
Async Command End: Update Build Number
Finishing: Get Tag/Set Build Version
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
