I am trying to set our build names to a format of...
$(BuildDefinitionName)_$(versionMajor).$(versionMinor).$(versionPatch)+$(SourceBranchName).$(SourceVersion)
e.g.
OurBigLibraryCI_1.2.3+master.10bbc577
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.
How would one shorten that in yaml based pipeline?
How would one shorten that in yaml based pipeline?
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.
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'
The result:
========================== 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
So, we could get the 7-digit version of $(SourceVersion) is cb12453
.
Hope this helps.