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.

5
  • No log in the drop folder? Try diagnostic build
    – KMoraz
    Mar 6, 2014 at 9:38
  • I do have logs. This question is about what is actually inside them - or more precisely what is not.
    – lapsus
    Mar 6, 2014 at 9:45
  • Did you try running with Verbosity=Diagnostic?
    – KMoraz
    Mar 6, 2014 at 9:57
  • In 2013 there is no such option anymore. I believe.
    – lapsus
    Mar 6, 2014 at 10:41
  • 1
    Ok Write-host appears in the build agent's log file. Write-verbose does not.
    – lapsus
    Mar 12, 2014 at 11:31

5 Answers 5

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.

5
  • Same behavior on TFS 2013 Update 3. And thank you for a nice, thorough description of your findings. Aug 23, 2014 at 20:44
  • Thank you SO much. Very helpful to find this. I've spent hours trying to figure this out.
    – FOO
    Mar 6, 2015 at 3: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, 2015 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: tfsbuildextensions.codeplex.com/SourceControl/latest#Scripts/… (but I did not try it)
    – bitbonk
    Mar 18, 2015 at 6: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 1, 2015 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.

1
  • 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 8, 2014 at 17:37
1

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

Disclosure: I'm the maintainer of this project.

0

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

1
  • 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, 2014 at 11:30

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.