问题描述
我正在尝试将我们的构建名称设置为...的格式
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-digit 版本.
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 位短版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!