Create log entries in Release Management

TL;DR

Creating log entries in Release Management can be challenging because standard output commands like Write-Host and Write-Output do not appear in deployment logs. To capture log information, you need to use Write-Verbose with the -verbose flag in your PowerShell scripts. Ensure your deployment scripts use this approach so you have logs for both successful and failed steps, which is important for troubleshooting and auditing.

12 December 2014
Written by Martin Hinshelwood
3 minute read
Comments
Subscribe

I have been working through my demos for NDC London next week. And I found it almost impossible to create log entries in Release Management where I wanted.

While in London for NDC 2014 I was in the same building as the filming of Mission Impossible 5. I worked on a TV show for my work experience at school and ended up with an IMDB profile and what always struck me was how much time was spent getting one a few minutes or even seconds of footage. If you ever get a chance to even be in the audience for a 30 minute comedy show, be warned… you will be there for at least 6 hours to get only 25 minutes of air time.

Sometimes the same thing happens for demos. My demo for NDC was an end to end presentation of Visual Studio ALM with VSO. For that I needed to have a full release pipeline for my application and as I just downloaded Fabirkam Fibre I had to create that release pipeline from scratch. While I was building this out I ran into a few issues and one that was kind of annoying was an inability to get a log to output so I could review what happened during the deployment.

If you have a deployment script it is really easy to fail it out. All you need to do is have an error occur, or deliberately call a “Write-Error” command. Simples. But what about having a log of the good things that happened?

clip_image001

If everything goes swimmingly then you get an empty space where the log should be. So how do I get an output. Well if I was creating a build script I could just have “Write-Host” and the build system would capture and log all the output.

#### Update Web.config
$config = Get-Content $destinationPathweb.config
$config = $config -replace "__connectionString__", $connectionString
Set-Content $destinationPathweb.config $config
Write-Host "Updated web.config"

Well lets try “Write-Host”…

clip_image002

Well, that’s not good. Looks like the Release Management team forgot to pipe the output that is intended for the “host” to the file. While “host” in the normal context is normally the “command prompt”, a script should not just fail because you are running it differently. You should always make sure that you pipe the output to the correct location for your context.

A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.

+At C:WindowsDtlDownloadsFabrikamFiber.WebDeploySimpleDeploy.ps1:31 char:1
+ Write-Host "destinationPath: $destinationPath"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo :NotImplemented: (:) [Write-Host], HostException
FullyQualifiedErrorId :HostFunctionNotImplemented,Microsoft.PowerShell.Commands.WriteHostCommand
Moo.. That’s just a nasty error that should never happen. SO lets try a simple "Write-Output" shall we.
Write-Output "applicationAnalyticsKey: $applicationAnalyticsKey"

clip_image003

Dam… “Write-Output” just disappears into the ether. It really should end up in the output but… well… it does not.. And “Write-Verbose” also end up nowhere, but that is a little more expected. At this point I am at a loss and ping the product team. Really, if I write something to the output and I would see it if running from the command line I want to see it in the log file. However for RM you need to explicitly declare output by using the “-verbose” command to tell PowerShell to actually write the verbose statements.

Write-Verbose "applicationAnalyticsKey: $applicationAnalyticsKey" -verbose

clip_image004

Well… now I get some output and a lovely log to view for later. While I may not ever look, when I do need something it will be there. Success logs are just as important as failure ones…

Smart Classifications

Each classification [Concepts, Categories, & Tags] was assigned using AI-powered semantic analysis and scored across relevance, depth, and alignment. Final decisions? Still human. Always traceable. Hover to see how it applies.

Comments
Subscribe

What to read next

Article Engineering Excellence

NDC London 2014: Why TFS no longer sucks and VSO is awesome

Overview of improvements in Team Foundation Server (TFS) and Visual Studio Online (VSO), including updated features, cloud integration, and …

Read article
Article DevOps

Create a Standard Environment for Release Management in Azure

Step-by-step guide to setting up a standard Azure environment for Release Management, including VMs, storage, networking, and Application …

Read article
Article Engineering Excellence DevOps

Create a Release Management pipeline for Professional Developers

Step-by-step guide to building an automated Release Management pipeline for professional developers, covering build, deployment, environment …

Read article
Article Engineering Excellence

Execute Tests with Release Management for Visual Studio 2013

Learn how to automate test execution during deployments using Release Management for Visual Studio 2013, including setup steps, environment …

Read article
Article Engineering Excellence DevOps

The High of Release

Overview of Microsoft’s new web-based Release Management tools for building flexible, integrated DevOps pipelines in VSTS and TFS, …

Read article