我有一个引用两个存储库的 Azure DevOps 管道:
我的想法是,我应该能够进行简单的配置更改并重新部署,而无需更改应用程序的版本号(因为代码没有更改)。但是,我仍然希望能够在版本号中看到配置在运行之间发生了变化。
因此,我正在考虑使用以下格式的版本号:
{major}.{minor}.{codeVersion}.{configVersion}
...具有以下限制:
{major}
和 {minor}
由开发者手动设置。{codeVersion}
没有更改,每次提交到code 存储库时,
{major}.{minor}
都应该自动递增。{configVersion}
没有更改,每次提交到config 存储库时,
{major}.{minor}.{codeVersion}
都应该自动递增。注意:我知道连续快速运行管道两次会导致两次运行的版本号相同。这是可以接受的,因为两者之间没有对任何存储库进行任何更改。 举个例子,我可能期望看到一堆具有以下名称的管道运行:
MyApp 0.1.0.0
MyApp 0.1.1.0
MyApp 0.1.1.1
MyApp 0.1.2.0
MyApp 0.1.2.0
函数,但它似乎没有达到我的需要。我的第一次尝试是这样的:
name: '$(Build.DefinitionName)-$(major).$(minor).$(codeVersion).$(configVersion)'
variables:
- major: 0
- minor: 1
- codeVersion: $[counter(format('{0}.{1}', variables['major'], variables['minor']), 0)]
- configVersion: $[counter(format('{0}.{1}.{2}', variables['major'], variables['minor'], variables['codeVersion']), 0)]
不幸的是,使用此代码,即使我没有对code
存储库进行任何提交,
codeVersion
值always 在每次运行时都会发生变化。然后,结果,configVersion
值始终为零。我尝试了上述方法的一些变体,其中我尝试引用 $(Build.SourceVersion)
变量来获取 git 提交 ID,但我还没有找到可行的解决方案。
根本问题似乎是,当提供的值没有更改时,计数器函数会递增,而我希望它在code存储库has的提交ID更改时递增。
编辑:修正拼写错误
GitVersion工具结合counter
功能自动生成期望的版本号。
GitTools 扩展安装到 Azure DevOps 组织。它提供了安装和执行用于语义版本控制的GitVersion工具的管道任务。
GitVersion.yml
文件。
# GitVersion.yml
mode: mainline
tag-prefix: '[vV]?'
assembly-informational-format: '{Major}.{Minor}.{Patch}'
major-version-bump-message: '\+semver:\s?(major)'
minor-version-bump-message: '\+semver:\s?(minor)'
patch-version-bump-message: '\+semver:\s?(code|app)'
no-bump-message: '\+semver:\s?(none|skip)'
commit-message-incrementing: Enabled
update-build-number: false
{major}
是您版本号中的
{major}
。
{minor}
是您版本号中的
{minor}
。
{Patch}
是您版本号中的
{codeVersion}
。
# azure-pipelines.yml
# Set the CI trigger.
trigger:
branches:
include:
- main
# Set the environment config repository as a repository resource.
# And enable resource trigger.
resources:
repositories:
- repository: config
type: git
name: envConfig
ref: main
trigger:
branches:
include:
- main
# Generate the part "{configVersion}" of the app version number.
variables:
configVersion: $[ counter(resources.repositories.self.version, 0) ]
steps:
- checkout: self
fetchDepth: 0
- task: gitversion/setup@3
displayName: 'Install GitVersion'
inputs:
versionSpec: '5.x'
preferLatestVersion: true
# Generate the part "{major}.{minor}.{codeVersion}" of the app version number.
# The task sets the variable "$(GitVersion.FullSemVer)" to pass the generated value.
- task: gitversion/execute@3
displayName: 'Generate Version'
# Combine the generated values to get the full app version number.
# Update the pipeline build/run number with the full app version number.
- bash: |
echo "##vso[task.setvariable variable=APP_VERSION;]$(GitVersion.FullSemVer).$(configVersion)"
echo "##vso[build.updatebuildnumber]$(GitVersion.FullSemVer).$(configVersion)"
displayName: 'Set App Version'
- bash: |
echo "APP_VERSION = $(APP_VERSION)"
displayName: 'Print App Version'
. . .
v0.1.0.0
”(请参阅“从提交视图创建标签”)。
azure-pipelines.yml
文件为应用程序代码存储库创建管道。
v0.1.0.0
”的最新提交时,生成的应用程序版本号是“
0.1.0.0
”。
分支时,CI 触发器会自动触发管道。 ‘{codeVersion}
’+1的数量。例如,完整的应用程序版本号从“
v0.1.0.0
”更改为“
v0.1.1.0
”。
分支时,资源触发器会自动触发管道。 ‘{configVersion}
’+1的数量。例如,完整的应用程序版本号从“
v0.1.1.0
”更改为“
v0.1.1.1
”。
分支时,CI 触发器会自动触发管道。 ‘{codeVersion}
’的数量+1,‘
{configVersion}
’的数量回到
0
。例如,完整的应用程序版本号从“
v0.1.1.1
”更改为“
v0.1.2.0
”。