[TFS 2015] 升級至 Update2 後,Build 會出現亂碼錯誤

2016/3/30 這天是 Microsoft 2016 Build 大會,同時也釋出了 TFS 2015 Update2,升級之後,沒想到引發了 Buil 失敗的錯誤,尋找解答時,也對 Build Agent 有了初步的認識,以下是我的問題及解法

伺服器環境:
  • Windows 2013 Datacenter x64 中文版,已執行線上更新
  • TFS 2015 Update2 中文版
發生原因:

TFS 2015 由 Updtae1 升級至 Update2,新版的 vNext Build Agent 在 Build 方案時會發生亂碼,導致 Build 失敗,如下圖:

舊版的 XAML 可 Build 成功,估計是新版 vNext Build Agent 的問題

於是我就跟微軟開了support case,經過幾天的往返,得到了以下解決方式,感謝 台灣微軟技術支援工程師 Albert Chiu

解決方式:

根據 error log看到問題發生在執行powershell指令時因為亂碼造成無法執行完畢

2016-04-05T18:48:46.2457438Z C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPath ''variable:PSHOME'' } else { Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1'')) ; Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1'')) }')) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; $env:TF_BUILD = 'True' ; Import-Module -Name 'C:\agent1\tasks\VSBuild\1.0.24\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList @{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''C:\agent1\tasks\VSBuild\1.0.24\VSBuild.ps1'''))"
2016-04-05T18:48:50.7188018Z ##[error]傳入了無效的物件,必須有 ':' 或 '}'。 (609): {
2016-04-05T18:48:50.7208012Z ##[error]  "loc.messages.PSLIB_ContainerPathNotFound0": "?曆??啣捆?刻楝敺? '{0}'",
2016-04-05T18:48:50.7218009Z ##[error]  "loc.messages.PSLIB_EndpointAuth0": "'{0}' ??蝡舫?隤?",
2016-04-05T18:48:50.7228008Z ##[error]  "loc.messages.PSLIB_EndpointUrl0": "'{0}' ??蝡舫? URL",


在GitHub上針對此問題的處理方式是在 powershell 指令上有用到 get-content 加上 -Encoding UTF8 後問題就解決了,如下圖:

其實不只一個 powershell 有這樣的問題,但只要根據 log 找出有問題的 powershell ,加上 -Encoding UTF8,就可以暫時解決這個問題
參考知識文件:

VstsTaskSdk Project https://github.com/Microsoft/vsts-task-lib/commit/e50fbad0cc629811d0384f9f266073907efe284e

若有謬誤,煩請告知,新手發帖請多包涵


Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET

Image result for microsoft+mvp+logo