Closed rupreck closed 9 months ago
That is correct and expected. The solution is build for build pipelines. Can mark this as a feature request.
Hello,
Thanks for getting back to me.
The documentation says for both Build and Release Pipelines as follows...
_"Version number counter is a Release and Build pipeline tasks that can increment a version number.
The default version number should be saved as a variable in the release or build pipeline. The task will increment the number based on your configuration."_
And in the Visual Studio Marketplace it is advertised as such:
It would be really helpful if it was updated to support Release Pipelines.
In the meantime the following PowerShell will successfully update a variable called Version within a Release Pipeline:
# Your Azure DevOps organization, project, and definition details
$organization = 'MyOrganisation'
$project = 'MyProject'
$releaseDefinitionName = 'MyPipeline'
$pat = 'My Personal Access Token'
# Access the Azure DevOps variable called Version
$variableName = $env:VERSION
# Split version number into components
$version = $variableName.Split('.')
$major = [int]$version[0]
$minor = [int]$version[1]
$patch = [int]$version[2]
# Increment version number
if ($patch -lt 10) {
$patch++
} else {
$patch = 0
if ($minor -lt 10) {
$minor++
} else {
$minor = 0
$major++
}
}
# Combine version number components back into a string
$newVersion = "$major.$minor.$patch"
# Base64-encode the Personal Access Token (PAT)
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
# Get all release definitions and find the one with the specified name
$url = "https://vsrm.dev.azure.com/$($organization)/$($project)/_apis/release/definitions?api-version=6.1-preview.4"
$definitions = Invoke-RestMethod -Uri $url -Method Get -ContentType 'application/json' -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$definitionId = $definitions.value | Where-Object { $_.name -eq $releaseDefinitionName } | Select-Object -ExpandProperty id
# Get the release definition by ID
$url = "https://vsrm.dev.azure.com/$($organization)/$($project)/_apis/release/definitions/$($definitionId)?api-version=6.1-preview.4"
$definition = Invoke-RestMethod -Uri $url -Method Get -ContentType 'application/json' -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
# Update the variable in the release definition
$definition.variables.$variableName.value = $newVersion
# Convert the definition back to JSON
$body = $definition | ConvertTo-Json -Depth 10
# Update the release definition
$response = Invoke-RestMethod -Uri $url -Method Put -Body $body -ContentType 'application/json' -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
# Output the response
Write-Output $response
Best,
Will
Ok will well check what is going wrong. Could you share a debug log file?
Describe the issue Version Number Counter Fails when used with Releases. Operates ok with Build Pipelines
To Reproduce Add to a Release Pipeline, set the variable and run.
Expected behavior As designed
Situation (please complete the following information):
Log info