在舊的TFS構建定義(XAML構建)中,如果代碼未更改,我可以選擇讓Team Build不再構建相同的代碼。 如何防止在新的TFS構建過程中重複構建vNext 2015
但是,在新的XML Build(vNext)中,我沒有看到這個選項,並且構建服務器一次又一次地構建代碼。有沒有什麼辦法可以達到我們在舊XAML構建定義中所做的相同行爲,即如果它沒有被更改,則不再構建代碼?
感謝您的幫助...
[UPDATE]
我寫了一個PowerShell腳本要達到什麼埃迪在回答表明
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
}
}
我添加了我寫你的建議powershell腳本。我也有相關的問題,我認爲在給定背景的情況下最好問這裏。我的問題是:現在我在每個請求的標題中使用我的PAT。由於此腳本是由構建定義運行的。我想知道是否可以用運行此構建定義的帳戶(例如服務帳戶)來替換我的憑證?我認爲這是可能的,否則其他構建任務(例如tfvc get)將無法訪問REST API。順便說一句,我使用的VSTS不是TFS的前提下,並且構建代理是在專用機器上。 – LxL
@LxL在構建定義設置下,選中「選項」選項卡下的「允許腳本訪問OAuth標記」。然後,您可以使用構建的oauth令牌訪問VSTS。 –
這裏是如何在腳本中使用OAuth的鏈接,以防其他人也像我一樣丟失https://www.visualstudio.com/docs/build/scripts/index#oauth – LxL