I’ve octopus variables under “Library” -> “Variable Sets” variables with names
- DatabaseExceptions
- ReportsExceptions
- App ParametersExceptions
- ApplicationExceptions
And I’ve setup of my project “Deployment process” in octopus as steps
- Database
- Reports
- App Parameters
- Application
- Send Email
The above variable are set with exceptions by using ‘PowerShell’ scripts that are invoked using predeploy.ps1 of the particular step on exceptions in scripts.
At the last step(Send Email) I was trying to send email with the information in exception variables by checking if particular variable has information in it.
I’m doing this in the send Email step body by checking the check box(“Body as HTML”)
<h2>Deployment Steps</h2>
<ol>
#{each step in Octopus.Step}
#{if step.Status.Code}
<li>#{step | HtmlEscape} —
#{if Step.Name == "Database"}
#{if Octopus.Action[Database].Output.DatabaseExceptions}
<pre>#{Octopus.Action[Database].Output.DatabaseExceptions}</pre>
#{/if}
#{/if}
#{if Step.Name == "Reports"}
#{if Octopus.Action[Reports].Output.ReportsExceptions}
<pre>#{Octopus.Action[Reports].Output.ReportsExceptions}</pre>
#{/if}
#{/if}
#{if Step.Name == "App Parameters"}
#{if Octopus.Action[App Parameters].Output.App ParametersExceptions}
<pre>#{Octopus.Action[App Parameters].Output.App ParametersExceptions}</pre>
#{/if}
#{/if}
#{if Step.Name == "Application"}
#{if Octopus.Action[Application].Output.ApplicationExceptions}
<pre>#{Octopus.Action[Application].Output.ApplicationExceptions}</pre>
#{/if}
#{/if}
</li>
#{/if}
#{/each}
</ol>
The Database and Reports scripts has errors and my output looks like below which is correct as expected
Deployment Steps
- Database — Exception on processing DB scripts - info:…
- Reports — Exception on processing Reports - info:…
- App Parameters
- Application
- Send Email
this is how I’m setting the octopus variable of Reports under Reports package in Predeploy.ps1 and same applies to Database package and App Parameters package too
if($reportExceptions) {
Set-OctopusVariable -name "ReportsException" -value $reportExceptions
}
And my Questions
Question 1:
Is it possible to do something as below as my step name and starting of my variable name are same
<h2>Deployment Steps</h2>
<ol>
#{each step in Octopus.Step}
#{if step.Status.Code}
<li>#{step | HtmlEscape} —
#{if Octopus.Action[#{step.Name}].Output.#{step.Name}Exceptions}
<pre>#{Octopus.Action[#{step.Name}].Output.#{step.Name}Exceptions}</pre>
#{/if}
</li>
#{/if}
#{/each}
</ol>
Question 2:
with in my teamcity build output has
- Database.buildversion.nupkg - which has scripts to deploy and predeploy.ps1
- Reports.buildversion.nupkg - which has scripts reports and predeploy.ps1
- App Parameters.buildversion.nupkg - which has App Parameters and predeploy.ps1
- Application.buildversion.nupkg - all my application code
- PatchNotes.txt
- ReleaseNotes.txt
can I create an octopus variable under “Library” -> “Variable Sets” with name say ‘exceptions’ and use it to set ‘exceptions’ variable from ‘predeploy.ps1’ if any exception occurs during ‘predeploy.ps1’ execution.
Lets say
in Database Package Predeploy.ps1
if($dbExceptions) {
Set-OctopusVariable -name "exceptions" -value $dbExceptions
}
in Reports Package Predeploy.ps1
if($reportsExceptions) {
Set-OctopusVariable -name "exceptions" -value $reportsExceptions
}
And back in Send Email Step can I use this ‘exceptions’ variable, to pull the exceptions occurred in individual deploy step
<h2>Deployment Steps</h2>
<ol>
#{each step in Octopus.Step}
#{if step.Status.Code}
<li>#{step | HtmlEscape} —
#{if Octopus.Action[step.Name].Output.exceptions} <!-- Question: does octopus pulls 'exceptions' variable based on scope of the current Step -->
<pre>#{Octopus.Action[step.Name].Output.exceptions}</pre>
#{/if}
</li>
#{/if}
#{/each}
</ol>