Include custom SQL script output in DM's deployment logs
swinghouse
Posts: 120 Bronze 2
In one of our Deployment Manager (DM) projects we let PostDeploy.ps1 run a customized SQL script like so:
This works, but it would be nice to have DM include the output (SQL Print statements in this case) from the SQL script file in the deployment log. Currently we get:
No script output in there!
Is it possible to get the script output in the DM deployment log? If so, what do we need to change?
/Mattias
sqlcmd.exe -b -V 1 -s $databaseServer -U $databaseUserName -P $databasePassword -i "RunMigrationScript.sql" -d "$databaseName"
This works, but it would be nice to have DM include the output (SQL Print statements in this case) from the SQL script file in the deployment log. Currently we get:
2013-05-30 15:43:53 DEBUG Looking for PowerShell scripts named PostDeploy.ps1
2013-05-30 15:43:53 INFO Calling PowerShell script: 'C:\ProgramData\Red Gate\DeploymentAgent\Applications\Production.Data\BagheraDataMigration\0.116\PostDeploy.ps1'
2013-05-30 15:49:08 DEBUG Script 'C:\ProgramData\Red Gate\DeploymentAgent\Applications\Production.Data\BagheraDataMigration\0.116\PostDeploy.ps1' completed.
2013-05-30 15:49:08 DEBUG Script output:
2013-05-30 15:49:08 DEBUG
2013-05-30 15:49:08 DEBUG Return code of PowerShell script: 0
No script output in there!
Is it possible to get the script output in the DM deployment log? If so, what do we need to change?
/Mattias
Comments
Deployment Manager should be capturing the std-out output from powershell scripts.
Windows powershell puts 'Out-Default' at the end of a pipeline, so what actually gets run is
Out-Default cannot process some objects. It can only handle a special type of formatting object produced by the shell’s formatting subsystem, according to this article:
http://technet.microsoft.com/en-us/maga ... 13852.aspx
Would you please run this command and check that it actually outputs something?
Thanks!
Chirayu
Software Engineer - Deployment Manager
Red Gate
Your suggestion worked beautifully!
After adding
to the sqlmcd call, the script output is indeed captured by Deployment Manager.
Many thanks!
/Mattias
Thanks!
Chirayu
Software Engineer - Deployment Manager
Red Gate
Firstly thank you for this topic as it has helped me get starting with creating a custom SQL deployment script using PowerShell. I'm just curious why you wouldn't use the more native command:
You would need to add SQL PowerShell Commandlets:
I've found the native Invoke-Sqlcmd to be much more adaptable as you can return result sets which can processed through ForEach if required.
Just curious and also thought this might help someone else reading this forum with an alternative option.
This brings me onto the fact that this error:
Did not cause the deployment to fail. Should I be doing something specific to capture errors? It is in a Try/Catch block so I'd have expected it to fail completely. It was only because I was checking the logs I picked it up.
Redgate Software
Thank you for the information. I'll go and remove those try-catch blocks...