问题描述
我正在尝试将我们的构建名称设置为...的格式
I am trying to set our build names to a format of...
$(BuildDefinitionName)_$(versionMajor).$(versionMinor).$(versionPatch)+$(SourceBranchName).$(SourceVersion)
例如OurBigLibraryCI_1.2.3+master.10bbc577
但是我找不到任何预定义的变量保存提交哈希的短"(7 位)版本.$(SourceVersion)
保存完整的 SHA-1 哈希.
However I coudn't find any predefined variable holding the "short" (7-digit) version of the commit hash. $(SourceVersion)
holds the full SHA-1 hash.
如何在基于 yaml 的管道中缩短它?
How would one shorten that in yaml based pipeline?
推荐答案
在 Azure Devops 中没有现成的变量来获取 $(SourceVersion) 的 7 位版本.因为 ShortSha
是 8 位的版本.
There is no out of box variable to get the 7-digit version of $(SourceVersion) in Azure Devops. Because the ShortSha
is 8-digit version.
所以,要解决这个问题,就像@4c74356b41 说的,我们必须使用 bashpowershell 脚本将长 sha 拆分为短 sha.
So, to resolve this issue, just like @4c74356b41 said, we have to use bashpowershell script to split long sha into short sha.
您可以查看我的以下示例了解更多详细信息:
You can check my following sample for some more details:
steps:
- script: |
echo $(Build.SourceVersion)
set TestVar=$(Build.SourceVersion)
set MyCustomVar= %TestVar:~0,7%
echo %MyCustomVar%
displayName: 'Command Line Script'
结果:
========================== Starting Command Output ===========================
##[command]"C:WINDOWSsystem32cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:VS2017Agent\_work\_tempe5f6293-77d8-41b7-a537-49e3b2e7bc6c.cmd""
cb124539c4cb7f19dc8e50e1b021f93c5ffaf226
cb12453
##[section]Finishing: Command Line Script
所以,我们可以得到 $(SourceVersion) 的 7 位版本是 cb12453
.
So, we could get the 7-digit version of $(SourceVersion) is cb12453
.
希望这会有所帮助.
这篇关于Azure Devops 中是否存在 $(SourceVersion) 的 7 位短版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!