Are there any properties etc. within MSBuild on TFS2015 (not XAML Builds) that will enable me to ascertain if the particular build was initiated manually or via a CI trigger?
I'm trying to avoid having two build definitions which differ only by a true/false value that is passed in as a property currently, e.g. with
/p:Manual=true
which I'm then using in my project as
$(Manual)
Without this, it looks like I need two definitions - one that's triggered via CI and passes as False in that property, the other manual that passes a True. If I had a means of finding out it the build was the result of a checkin then I could get away with needing two.
Just to clarify, I'm aware there's no property on the Build definition, I'm looking for something WITHIN the actual MSBuild process (as it's running) that would allow me to ascertain this.
At this point even getting the Login Id of the user who scheduled the build would do - if it's a triggered build my guess is that would be the Service account running TFS, otherwise it's a human.
To expand on Dhruv's answer, here is the relevant Powershell code to record the build reason for TFS 2015:
# Retrieve build reason via REST API call and set as TFS 'Build.BuildReason' variable
$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECT/_apis/build/builds/$env:BUILD_BUILDNUMBER`?api-version=2.0"
$header = @{"Authorization" = "Bearer $env:SYSTEM_ACCESSTOKEN"}
$response = Invoke-RestMethod $url -Headers $header
$reason = $response.reason
Write-Host "##vso[task.setvariable variable=Build.BuildReason;]$reason"
Call it in a Powershell step before any steps that need to reference the build reason.