Accessing output variables that are run on Octopus Server

dstevens's Avatar

dstevens

08 Nov, 2017 07:10 PM

Hello,

I'm trying to include a section in the email notification template that will let everyone know if there were any warnings during the deployment. I have a powershell script step in my process that gets the content of the task log and increments a variable called $warningsCount anytime a line contains the word 'warning'. I know this isn't the best solution but it will work for the time-being. That same script has the following lines:

if($warningsCount > 0) {
    Set-OctopusVariable -name "DeployedWithWarnings" -value "True"
    Set-OctopusVairable -name "DeploymentWarningsCount" -value $warningsCount
}

The issue is, I cannot access either of those variables in the email template step or a dummy step later in the process. I'm attempting to access it by calling:

$warnings = $OctopusParameters["Octopus.Action[Test1].Output.DeploymentWarningsCount"]
Write-Host($warnings)

But there is nothing written to the console. Am I accessing it wrong? Any help would be great!

I'm using Octopus v3.3.10

Thanks,

Derek

  1. Support Staff 1 Posted by Alex Rolley on 09 Nov, 2017 06:46 AM

    Alex Rolley's Avatar

    Hi,

    Thanks for getting in touch!

    You were very close with your script, the only change needed is that for Powershell to evaluate > you need to use -gt, so it wasn't actually entering your loop to set the variable values. You also had misspelt the second Set-OctopusVariable, but we've all done that :)

    if($warningsCount -gt 0) {
        Set-OctopusVariable -name "DeployedWithWarnings" -value "True" 
        Set-OctopusVariable -name "DeploymentWarningsCount" -value "$warningsCount"
    }
    

    Using the updated code I can then use the output variable correctly in a later step.

    Please let me know if you have any other questions,

    Regards,
    Alex

  2. 2 Posted by dstevens on 09 Nov, 2017 02:55 PM

    dstevens's Avatar

    Welp, those were some silly mistakes. Thanks Alex!

  3. Support Staff 3 Posted by Alex Rolley on 12 Nov, 2017 11:16 PM

    Alex Rolley's Avatar

    No problems :)

    Happy deploying!

    Alex

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac