Reputation: 1948
In the old TFS build definition(XAML builds), I have an option to make Team Build not build the same code again if the code hasn't been changed.
However, in the new XML Build (vNext), I don't see this option and the build server keeps build the code again and again. Is there any way I could achieve the same behavior that we had in the old XAML build definition in term of not building the code again if it hasn't been changed?
Thank for your help...
[UPDATE]
I wrote a powershell script to achieve what Eddie suggested in the answer
Write-Debug -Message ("System URL: "+$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)
Write-Debug -Message ("Team Project Name: "+$env:SYSTEM_TEAMPROJECT)
$baseURI=$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI+"DefaultCollection/"+$env:SYSTEM_TEAMPROJECT+"/_apis/"
$oauth= @{Authorization="Bearer $env:SYSTEM_ACCESSTOKEN"}
Write-Debug -Message ("Base URL: "+$baseURI)
$BuildDefList=(Invoke-RestMethod -Uri $baseURI/build/definitions?api-version=2.0 -Headers $oauth -Method Get).value | where {$_.name -like "*Build"}
Write-Host -ForegroundColor Cyan -Object ("Found "+$BuildDefList.count+" build definition(s)")
foreach ($buildDef in $BuildDefList)
{
Write-Host -ForegroundColor Yellow -Object ("Checking Build Definition: "+$buildDef.name+" ...")
$id=$buildDef.id
$build= Invoke-RestMethod -Uri $baseURI/build/builds?api-version=2.0"&"definitions=$id"&"`$top=1"&"resultFilter=succeeded -Headers $oauth -Method Get
$changeset= $build.value.sourceVersion
"The changeset used in the lastest build in this build definition is "+$changeset
$sourceBranch=$build.value.sourceBranch
$latestChangeset=(Invoke-RestMethod -Uri $baseURI/tfvc/changesets?api-version=1.0"&"searchCriteria.itemPath=$sourceBranch"&"`$top=1 -Headers $oauth -Method Get).value.changesetId
"The latest changset need to build is "+$latestChangeset
if($latestChangeset -and $changeset -lt $latestChangeset)
{
Write-Host -ForegroundColor Green -Object ("The build is old. Queuing new build for "+$buildDef.name+" now")
$body= @{Definition = @{ Id=$id}} | ConvertTo-Json
Invoke-RestMethod -Uri $baseURI/build/builds?api-version=2.0 -Body $body -ContentType "application/json" -Headers $oauth -Method Post
}
}
Upvotes: 1
Views: 298
Reputation: 29958
There is no option to configure this in vNext build definition. There are several feature requests submitted for this feature on VSTS User Voice.
Add an vNext option to build only if something has changed to scheduled build trigger
TFBuild 2015: Run sheduled build only when source has changed
To achieve this feature for now, you can create another build definition and set it to scheduled build. In the build definition, just add a power-shell script task to compare the current source version and previous build source version. If the current version is newer than the built one, then trigger the real build definition to build the code via Rest API.
Upvotes: 3