TFS 2013 default template run powershell script and log output

lapsus picture lapsus · Mar 6, 2014 · Viewed 8.6k times · Source

running a powershell script from within a build process has become really really straight forward with VS 2013. Unfortunately no write-host commands are being logged to the tfs build log.

So after a build completed I cannot look into the log file and see what the powershell shell script actually did.

The log file only says:

Run optional script after MSBuild 00:03
Run optional script before Test Runner 00:00
Run VS Test Runner 00:00
Run optional script after Test Runner 00:00
...

The ActivityLog.AgentScope.1.xml log file is more talkative but still has too few information.

Run optional script after MSBuild00:00:03
InputsEnvironmentVariables: 
Enabled: True
Arguments: 
FilePath: $/CMP04/Some/Project/Main/Web/.scripts/CI/CI.ps1

OutputsResult: 0

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -NoProfile -NonInteractive -File "D:\ws_build\1\CMP04\IP-Main\src\Some\Project\Main\Web\.scripts\CI\CI.ps1"

Any idea how I can get any debugging information into the tfs build logs? I could of course create an extra log file, but that is plan b :)

edit: write-host is being logged to the agent's log xml. write-verbose is not.

Answer

deadlydog picture deadlydog · May 8, 2014

Explicitly setting the verbosity on the default build templates is gone in VS 2013; instead every build logs diagnostic info. The raw data gets dumped to the agent's xml log in the Build Drops folder as you mentioned. To get a nice view of it though, you have to access it from the Team Web Access; you can't from Visual Studio anymore, which makes sense since viewing those diagnostic logs in Visual Studio would usually cause VS to hang.

So to view the diagnostic log in the Team Web Access, you can either:

  • If using VS 2013, you can just right-click on the build in the Build Explorer and choose Open in Browser.

or

  • From your Team Project page in the Team Web Access, select the Build tab, find the build you are interested in and double-click it, and then select the Diagnostics tab.

The following is what I have found from my experimentation on TFS 2013 Update 2:

In the build Summary and Log views (the only 2 views available from within VS), only Write-Error messages will show up. Using Write-Error in your PowerShell scripts will not mark your build as Failed, but instead will cause it to Partially Succeed.

In the Diagnostics view, Write-Host, Write-Output, Write-Warning, and Write-Error will all show up. Write-Verbose and Write-Debug do not show up though, even if you pass the -Verbose and -Debug switches as a PowerShell script argument.