Build.SourceVersion is blank in VSO vNext Build

前端 未结 3 1241
耶瑟儿~
耶瑟儿~ 2020-12-11 04:00

I am using the new scriptable build features in Visual Studio Online (not the XAML build definitions), and I am trying to have the build version number include the latest Gi

相关标签:
3条回答
  • 2020-12-11 04:21

    I'm afraid it is not able to use $(SourceVersion) in the build number format. However, I think you can use PowerShell to change build number to be $(SourceVersion), and you need to include the PowerShell in your build process. Check this link for the details.

    And you can define the PowerShell to be similar to:

    [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()
    
    0 讨论(0)
  • 2020-12-11 04:28

    I was able to use $(Build.SourceVersion), but only when builds were triggered automatically on commit (on Continuous integration). It turns out to be empty only if I queue it manually:

    I'm using the following Build number format:

    $(BuildDefinitionName)_$(date:yyyyMMdd)_$(Build.BuildId).$(Build.SourceVersion)$(rev:.r)
    
    0 讨论(0)
  • 2020-12-11 04:28

    NeoGarRiGus - it turns out empty because when you run a manual build you have to enter the Source Version field in order for it to populate. The CI inputs that value automatically when a Dev check's in but when you queue a build manually there is a blank field in the pop-up that allows you to enter the Source Version:

    Source Version Field in VSTS

    0 讨论(0)
提交回复
热议问题