本文介绍了Azure Devops中是否有$(SourceVersion)的短7位数字版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将内部版本名称设置为...

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所说的那样,我们必须使用bash \ powershell脚本将长阴影分割成短阴影.

So, to resolve this issue, just like @4c74356b41 said, we have to use bash\powershell 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:\WINDOWS\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:\VS2017Agent\_work\_temp\be5f6293-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位数字版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 16:33