问题描述
我在 Azure DevOps 中进行了设置,并且正在尝试配置 GitVersion 以进行版本控制。工作正常,除了修补程序的拉取请求
示例: 修补程序分支的构建给了我 1.2.3-beta 版... 该修补程序分支的拉取请求开始给出 med 1.3.0-PullRequest
我希望它是 1.2.3-PullRequest。
我做错了什么??
解决方法
如何在 Pull Request 的构建管道定义中设置构建号?
根据您的评论,您希望 PR 版本与 hotfix
分支的最新版本具有相同的版本号,但后缀除外,对吗?
如果是这样,您可以尝试在 PR 的构建管道中设置并运行如下所示的 shell 脚本(PowerShell 作为此处的示例)。
# 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"
说明:
-
REST API“Builds - List”中的参数。
- “
definitionID
”是修补程序分支的构建管道的 ID。 - '
branchName
' 是 PR 的源分支(例如refs/heads/hotfix
),您可以直接使用 {{3} } '$(System.PullRequest.SourceBranch)
' 获取分支名称。 - 将“
$top
”的值设置为1
。这将使 API 调用仅返回最新版本。
- “