TFS 2013 default template run powershell script and log output

浪子不回头ぞ 提交于 2019-12-05 20:20:38

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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

Disclosure: I'm the maintainer of this project.




回答5:


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



来源:https://stackoverflow.com/questions/22219932/tfs-2013-default-template-run-powershell-script-and-log-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!