Octopus.Action[STEPNAME].Output is not an option

HI,

We are trying to use an output variable from the previous action step in an Email step.

We are version 2019.12.2

When we try to reference a variable for the subject, we want to reference this:
#{Octopus.Action[Extract Build Info].Output.Branch}

While the variable up to this point. “Octopus.Action[Extract Build Info]” is available, the .Output is not an option.

Instead it suggests .RunOnServer
.Script.ScriptBody
.Script.ScriptSource
.Script.Syntax
.TargetRoles

So we are not able to access the output variable.

Is there something else we need to specify so make .Output available? I feel like it should be present for our version (yes it’s outdated) but I see posts from previous versions talking about it.

FYI this is what I have in my previous steps script

$branch = “HI”
Set-OctopusVariable -name “Branch” -value $branch

And here are the auto populated drop down variable suggestions I see.

Notify_Slack_of_Deployment_-_Octopus_Deploy

If i try to force it like this:

The subject like looks like:

QA6-Azure has #{Octopus.Action[Extract Build Info].Output.Branch}

So clearly it is just interpreting it literally.

Hi @mevans,

Thanks for reaching out! I’m sorry you are having trouble with this particular output variable feeding into your email subject line, but I would be happy to help take a closer look at this. In reviewing the information you’ve provided so far it does look like your syntax is correct, so we’ll need to dive a little deeper on this.

As a first step, would you be able to enable verbose variable output for this project and run through another deployment to see what all gets outputted? Enabling these variables within your project will force Octopus to print all relevant variables in the deployment task log. Feel free to upload the new task log at the following secure link for review if you’d like our team to take look.

I hope this helps shed some light on the underlying problem, but let me know if I can be of any more help.

Best regards,

Britton

I’m doing this now.

@britton.riggs

While the deploy is happening, I just feel like it is concerning that the auto population of available variables for me to use do not include the .Output variable?

Can you confirm if my version (2019.12.2) should have the ability to access the .Output form an Octopus.Action[StepName].Output.X

After looking at the logs i see:

Searched for targets:  
August 18th 2022 14:59:18Verbose
 * specifically matching these ids: Machines-101
 * that are enabled
 * with no id exclusions
 * with no environment exclusions
 * has a role that overlaps: WWW App
 * with no tenant exclusions
 * with any health status
 
August 18th 2022 14:59:18Info
Skipping this step as no matching targets were found 

So i set it to run on the server (i had it set to run on targets), rerunning now.

1 Like

Hi @mevans,

Thank you for the updates!

In doing some research on my side I was able to find some help posts where individuals were using this feature back in 2015, so your version of Octopus Deploy should support this as well.

Let me know what you find out in reviewing the verbose log output, but hopefully this provides some direction on troubleshooting this further.

Best,

Britton

Is there a way to test the output values quickly from a past deploys data?

It takes 5-10 minutes to deploy and so I have to wait that long just to see what is being written out.

I want to run this script:
Which I found here: Using build information for visibility across your CI/CD pipelines - Octopus Deploy

I’m trying to Grab the Branch name from it.

$changeListRaw = $OctopusParameters["Octopus.Deployment.Changes"]
$changeList = $changeListRaw | ConvertFrom-Json

foreach ($change in $changeList)
{
    $emailBody = "Release Number: $($change.Version)`r`n"

    $emailBody += "    Build Information`r`n"
    foreach ($buildInformation in $change.BuildInformation)
    {
        $emailBody += "        Package: $($buildInformation.PackageId)`r`n"
        $emailBody += "        Version: $($buildInformation.Version)`r`n"
        $emailBody += "        BuildUrl: $($buildInformation.BuildUrl)`r`n"
        $emailBody += "        VCSRoot: $($buildInformation.VcsRoot)`r`n"
        $emailBody += "        VCSCommitNumber: $($buildInformation.VcsCommitNumber)`r`n"
    }

    $emailBody += "    Commit Information`r`n"
    foreach ($commit in $change.Commits)
    {
        $emailBody += "        Git Hash: $($Commit.Id)`r`n"
        $emailBody += "        Git Comment: $($Commit.Comment)`r`n"
        $emailBody += "        Git Link: $($Commit.LinkUrl)`r`n"
    }

    $emailBody += "    Work Items`r`n"
    foreach ($workItem in $change.WorkItems)
    {
        $emailBody += "        Id: $($WorkItem.Id)`r`n"
        $emailBody += "        Link Url: $($WorkItem.LinkUrl)`r`n"
        $emailBody += "        Source: $($WorkItem.Source)`r`n"
        $emailBody += "        Description: $($WorkItem.Description)`r`n"
    }
}

Set-OctopusVariable -name "EmailBody" -value $emailBody

So small progress, after setting the task to run on the server I was able to get the value “HI” for the .Output,

So our learning is that octopus does not auto suggest .Ouput (at least in my version)

But Then I tried to replace the very basic scrip with this:

$changeListRaw = $OctopusParameters["Octopus.Deployment.Changes"]
	$changeList = $changeListRaw | ConvertFrom-Json

    foreach ($change in $changeList)
    {
        $commits = ""
        $branch = ""
        $version = ""
        

        $emailBody += "    Build Information`r`n"
        foreach ($buildInformation in $change.BuildInformation)
        {
            $version = "$($buildInformation.Version)`r`n"
            $branch = "$($buildInformation.Branch)`r`n"
        }

        $emailBody += "    Commit Information`r`n"
        foreach ($commit in $change.Commits)
        {
            $commits += "        Git Hash: $($Commit.Id)`r`n"
            $commits += "        Git Comment: $($Commit.Comment)`r`n"
            $commits += "        Git Link: $($Commit.LinkUrl)`r`n"
        }
        
    }

Set-OctopusVariable -name "Commits" -value $commits
Set-OctopusVariable -name "Branch" -value $branch
Set-OctopusVariable -name "version" -value $version

Hoping to extract the branch and version and Branch is empty, so I need to debug this, but waiting for deploys is brutal. Is there some console I can retest the script against past runs?

Hi @mevans,

Thanks for providing more detail around your process.

Unfortunately, as this deals with step output variables you would need to run through a deployment to test this properly. This is also why you are unable to pre-select the variable via drop-downs, as this output variable is generated dynamically during the deployment process.

A couple of things you could try to speed up the debugging process would be to break these specific steps out into their own project/runbook temporarily (using the "Run a Script step template) so you can isolate the problem, or alternatively you could redeploy your existing project and exclude any steps that are not relevant to your current testing.

Best,

Britton

Ok, so I have made a little progress perhaps you can point me in the right direction.

I’m trying to use the script that i referenced above (also referenced here)

I’m hoping to be able to get the actual Branch name.

But when i grab the changes JSON and write it out as JSON

the BuildInformation is empty.

[{"Version":"1.3.0.18722-master-86a568f018-587","ReleaseNotes":null,"BuildInformation":[],"WorkItems":[],"Commits":[]}]

So I thought perhaps it’s empty because I hadn’t set a Package Id, but then when i set package Id,

I get an error

[Octopus Deploy] Creating release...
[04:50:54]	[Octopus Deploy] Error from Octopus server (HTTP 400): There was a problem with your request.
[04:50:54]	[Octopus Deploy] 
[04:50:54]	[Octopus Deploy]  - No package version was specified for Extract Build Info:XXX.CorporateSite.Web.Site
[04:50:54]	[Octopus Deploy] 

Well of course i didn’t specify a version in that step, it doesn’t give me an option to do so… Nor would i want to i just want it to grab the Build info the package currently being deployed.

How can I do this?

Actually what I just realized is that the error is being thrown
during the Create Release step which is called from TeamCity.

But it only happens when I have a build step that references a package.

I think I didn’t understand what that did so i have since removed the package reference.

So I’m back to the question, why is the value behind :

Octopus.Deployment.Changes basically empty?

I’m now going to see if i can directly view this variable:

Octopus.Deployment.PackageBuildInformation

Maybe that has it

The question is how do I access this piece of data pointed to in the green arrow from a power shell script. I’m trying to send it to a slack channel.

Hi @mevans

You can access the build information by calling against /space-id/build-information. You can view the calls you can perform by accessing the SwaggerUI on your URL (which is your base URL and swaggerui/index.html just in case you haven’t accessed it before).

You can get build information by a list or ID, and then on each build information object, you will have a branch property.

Hope this helps!
Kind Regards
Sean

Hi @mevans,
Just stepping in for Britton!

Your script for extracting the variables looks fine and works ok on my end, I’d just like to confirm how you are trying to output the variables in the Slack notification step?

I just tested outputting the variables to the log in a Run a script step, however it should be very similar to the following for the Slack step:

write-host $OctopusParameters[“Octopus.Action[Extract Build Info].Output.Commits”]
write-host $OctopusParameters[“Octopus.Action[Extract Build Info].Output.Branch”]
write-host $OctopusParameters[“Octopus.Action[Extract Build Info].Output.Version”]

I found this blog is great for demonstrating how output variables work:

Let me know how you get on or if you had any questions!

Best Regards,

So i’m using power shell in a build step, is there an power shell method that calls this API?
In the context of a build step, how do I get the correct id of the resource to call the


API?