Build.SourceVersion is empty in VSO vNext Build

I am using the new scripting capabilities in Visual Studio Online (rather than the XAML assembly definition), and I am trying to ensure that the build version number includes the latest Git Commit ID of the target repository using the build number format.

I use the following assembly number format:

$(MajorVersion).$(MinorVersion).$(BuildId).$(SourceVersion) 

The result is the generated version number 1.0.1234. - that is, the value of SourceVersion is empty, which causes an error in VSO when the build order is. I also tried to qualify a variable by prefixing it with Build. with the same result. To check, I changed the build number in the following format:

 $(MajorVersion).$(MinorVersion).$(BuildId).$(SourceBranch) 

This correctly results in a value of 1.0.1234.refs_heads_master

I used Predefined Variables and Build.SourceVersion are listed as a global variable.

Am I doing something wrong, am I facing an error or is it by design and unavailable at the time of assembling the assembly in the queue? If this is by design, is there a way to automatically include a short Git Commit ID in assembly number format?

Here I set the build number format in VSO: Here I set the build number format in VSO

This is the error that I see when I do not explicitly specify Git CommitId:

400: Build number format string $ (MajorVersion). $ (MinorVersion). $ (BuildId). $ (SourceVersion) generated build number 0.1.1. which contains invalid character (s) is also long or ends with ".". The maximum length of the build number is 255 characters. Characters that are not allowed include "," / ",": ", '<', '>', '\', '|', '?', '@' And '*'.

+7
git vsts vsts-build
source share
3 answers

I am afraid that he will not be able to use $(SourceVersion) in assembly number format. However, I think you can use PowerShell to change the build number as $(SourceVersion) , and you need to include PowerShell in the build process. Check out this link.

And you can determine what PowerShell will look like:

 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client") [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client") [System.Reflection.Assembly]::LoadWithPartialName("System.Net") [String] $CollectionUrl = "https://vsoserver.visualstudio.com/defaultcollection" [String] $BuildUrl = $env:BUILD_BUILDURI $netCred = New-Object System.Net.NetworkCredential("username","password") $basicCred = New-Object Microsoft.TeamFoundation.Client.BasicAuthCredential($netCred) $tfsCred = New-Object Microsoft.TeamFoundation.Client.TfsClientCredentials($basicCred) $teamProjectCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection($CollectionUrl,$tfsCred) $buildServer = $teamProjectCollection.GetService([type]"Microsoft.TeamFoundation.Build.Client.IBuildServer") $buildDetail = $buildServer.GetBuild([Uri]$BuildUrl) $buildDetail.BuildNumber = $Env:BUILD_SOURCEVERSION $buildDetail.KeepForever = $true $buildDetail.Save() 
+2
source share

I was able to use $(Build.SourceVersion) , but only when assemblies were automatically triggered upon commit (during continuous integration). It turns out to be empty only if I queued it manually:

Queue Build Scenario

I use the following assembly number format:

 $(BuildDefinitionName)_$(date:yyyyMMdd)_$(Build.BuildId).$(Build.SourceVersion)$(rev:.r) 
+2
source share

NeoGarRiGus - it turns out to be empty, because when you start manual assembly, you must enter the "Source version" field so that it is filled. CI enters this value automatically when the check is Dev, but when you queue the build manually, an empty field appears in the pop-up window that allows you to enter the original version:

Source Version Field in VSTS

+1
source share

All Articles