10

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.

lapsus
  • 2,915
  • 2
  • 32
  • 61

5 Answers5

21

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.

deadlydog
  • 22,611
  • 14
  • 112
  • 118
  • Same behavior on TFS 2013 Update 3. And thank you for a nice, thorough description of your findings. – JamesQMurphy Aug 23 '14 at 20:44
  • Thank you SO much. Very helpful to find this. I've spent hours trying to figure this out. – FOO Mar 06 '15 at 03:58
  • Viewing the output of Write-Host once the build has finished in the Diagnostics tab works great, but how about getting Write-Host output during the build? – SmudgerDan Mar 12 '15 at 16:05
  • 2
    To show verbose output from `Write-Verbose` you have to set the `-verbose` flag for the script in the build definition. To make this flag work you have to set the `[CmdletBinding()]` atribute in your script. I got this hint from this script: https://tfsbuildextensions.codeplex.com/SourceControl/latest#Scripts/GatherItemsForDrop.ps1 (but I did not try it) – bitbonk Mar 18 '15 at 06:23
  • setting '[CmdletBinding()]' in script and the -verbose Parameter in the build definition does the trick. In the diagnose-Web View of the Build I get a lot of 'VERBOSE: ...'-Messages for my Write-Verbose cmdlet. – gReX Jul 01 '15 at 13:56
4

If you are using TFS 2013 Default Template, you can check your Diagnostic logs in your "Team Web Access" under Builds, select the build you want to display the logs and then you will see three options:

Summary Log Diagnostics

Click in Diagnostics link and you will see a very detail logs including the powershell scripts outputs.

Moises.

1

I had this problem as well. I had 4 lines of writing "debug" information in 2013. You must only use Write-Host for debug information. If one of your lines is in example Write-Verbose, all the Write-Host will not show op in the diagnotics tab of your build. I tested this with TFS2013 Update 2.

You can use Write-Host and Write-Warning together.

LockTar
  • 5,364
  • 3
  • 46
  • 72
  • I just tested using Write-Host, Write-Output, Write-Verbose, Write-Warning, Write-Error, and Write-Debug all multiple times from the same PowerShell script, and they all showed up in the Diagnostics log, except for Write-Verbose and Write-Debug. Those ones seem to never get logged. – deadlydog May 08 '14 at 17:37
1

You can view build logs in much greater details using BuildExplorer.

Disclosure: I'm the maintainer of this project.

Jonathan
  • 6,939
  • 4
  • 44
  • 61
0

If you want capture Write-Host, you can use Start-Transcript. More than TFS you need to think about what and how log.

Giulio Vian
  • 8,248
  • 2
  • 33
  • 41
  • 1
    Start-transcript didn't work. It did create the logfile and everything but it didn't actually write anything into it. It does though when I run the script manually. I'll have to investigate in that. – lapsus Mar 12 '14 at 11:30