我試圖在我們的團隊項目之一中使用PowerShell創建預構建步驟,以增加該VS解決方案中所有程序集/應用程序的構建編號。這是爲TFS2015更新2.從PowerShell的構建步驟訪問TFS TeamProjectCollection
我發現了一些示例代碼在這裏和那裏在線,並拼湊在一起,我想象會工作。我可以在TFS服務器上手動運行powershell腳本(以Windows帳戶身份驗證到服務器),並且工作正常,但它在構建過程中無法正常運行。
這裏是示例代碼的問題,我不斷收到我的錯誤。它與認證/連接到TFS服務器來做:
$CollectionUrl=New-Object System.Uri("$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI")
$BuildUrl="$env:BUILD_BUILDURI"
# get the team project collection
$TeamProjectCollection=[Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($CollectionUrl)
# get the build server
$BuildServer=$TeamProjectCollection.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
# get the build detail
$BuildDetail=$BuildServer.GetBuild($BuildUrl)
# get the build definition
$BuildDefinition=$BuildDetail.BuildDefinition
有錯誤,我得到的是:
Exception calling "GetService" with "1" argument(s): "TF30063: You are not authorized to access http://servername/TPCName
我已經使用上述兩種調用來獲取TPC嘗試和建築工因爲它並不工作。
$TeamProjectCollection=New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection($CollectionUrl)
於是我開始嘗試建立一個基於我的登錄憑據到服務器的憑證對象,看看我是否能連接到TPC的方式。仍然無法正常工作(在服務器上或構建過程中),但不同的錯誤:
$netCred = New-Object System.Net.NetworkCredential($username,$password)
$basicCred = New-Object Microsoft.TeamFoundation.Client.BasicAuthCredential($netCred)
$tfsCred = New-Object Microsoft.TeamFoundation.Client.TfsClientCredentials($basicCred)
# get the team project collection
$TeamProjectCollection=New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection($CollectionUrl, $tfsCred)
拋出異常:
Exception calling "GetService" with "1" argument(s): "TF400324: Team Foundation services are not available from the server.
我也盡我所能在修改TFS權限的Windows帳戶TFS服務運行以確保那裏沒有問題。我很確定我將它添加到了我的身份所在的所有角色/組中,但仍然無法驗證身份。
在這一點上我很茫然。有人可以幫助我弄清楚如何使用定義的憑證正確連接到TFS服務器,或幫助我調整服務帳戶,身份,配置選擇等的權限;需要訪問teamProjectCollection。
您使用哪種構建系統? vNext或XAML?根據您的描述,您希望增加內部版本號,但是powershell腳本正在獲取構建定義。你想達到什麼功能? –