Reputation: 11
I have a setup in Azure DevOps and are trying to configure GitVersion to do our versioning. Works fine except for pull requests of hotfixes
example: build of hotfix branch gives me version 1.2.3-beta... pull request of that hotfix branch starts gives med 1.3.0-PullRequest
I expected it to be 1.2.3-PullRequest.
What am I doing wrong??
Upvotes: 1
Views: 658
Reputation: 141
What you need to use is the default gitversion configuration that you can configure using gitversion init
.
Each PR increments the patch
version - 1.1.1
. So each PR is considered a hotfix. What you need to do then is you need to add commit message +semver:minor
to bump the minor
version - 1.2.0
. If you would like to leave it as a hotfix do not include the commit message.
Then you promote the build from main
to your live environment and tag your main
branch with 1.2.0
manually or automatically.
This is assuming you are using the default ContinuousDelivery
mode.
Upvotes: 0
Reputation: 13824
How do you set the build number in the build pipeline definition for Pull Request?
According to your comments, you want the build for PR has the same build number with the latest build for the hotfix
branch, except the suffix, right?
If so, you can try set up and run a shell script (PowerShell as example here) like as below in the build pipeline for PR.
# Convernt PAT to Base64 string
$pat = "personal access token"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $pat)))
# Set up headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", ("Basic {0}" -f $base64AuthInfo))
$headers.Add("Content-Type", "application/json")
$uri = "https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitions={definitionID}&branchName=$(System.PullRequest.SourceBranch)&`$top=1&api-version=6.1-preview.6"
# Run the API and return the response body
$response = Invoke-RestMethod -Uri $uri -Headers $headers -Method GET
# Get buildNumber of the latest build for hotfix branch
$buildNumber_hotfix = $response.value[0].buildNumber
Write-Host "$buildNumber_hotfix"
# Replace the suffix
$buildNumber_PR = $buildNumber_hotfix.replace("beta","PullRequest")
Write-Host "$buildNumber_PR"
# Update the buildNumber of current build for the PR
Write-Host "##vso[build.updatebuildnumber]$buildNumber_PR"
Description:
Parameters in the REST API "Builds - List".
definitionID
' is the ID of the build pipeline for hotfix branch.branchName
' is the source branch of the PR (e.g. refs/heads/hotfix
), you can directly use the predefined variable '$(System.PullRequest.SourceBranch)
' to get the branch name.$top
' as 1
. This will let the API call only return the latest build.Upvotes: 1