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.
Jason did, though. He’s created a Windows PowerShell script that wraps the tfpt createteamproject command, and he made it publicly available: New-TFSTeamProject.ps1. I then wanted to create a cmdlet to help me know what users belong to what teams in TFS.
In fact, the TFS Power Tools contain a set of cmdlets for version control and a few other functions. There is one issue when downloading them, however. The "typical" installation of the Power Tools leaves out the Windows PowerShell cmdlets! So make sure you choose "custom" and select those Windows PowerShell cmdlets manually.
You can leverage the Write-Warning & Write-Error PowerShell commands to display warnings and errors, or you can use the TFS specific task.logissue command to ensure the warnings and errors appears in the build summary. Here are the various commands: 1.
You can use simple text log files to control running and track all of the activities in your PowerShell scripts. This is useful when debugging errors or auditing script actions. In this article, we’ll show some ways to use logging in PowerShell scripts by writing output to text log files.
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:
Open in Browser
. or
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With