How to get package version number and pass it to the sql execution task?

yvenchka.kwan's Avatar


21 Feb, 2018 01:20 AM

Hi Octopus Team,

I am currently using Octopus v4.1.9 and I am trying to get the Major, Minor values from the Octopus.Action.Package.PackageVersion system variable, so i can pass them into a task created using the community SQL - Execute Script step template, and in return these Major & Minor values of the package will be entered into the database tables as necessary.

After some reading from the awesome forum, I have tried putting a step before the sql execution step to extract the version using the following powershell script:

[system.version]$V = $OctopusParameters['octopus.action.package.packageversion']
Set-OctopusVariable -name "Major" -value $v.Major
Set-OctopusVariable -name "Minor" -value $v.Minor
Set-OctopusVariable -name "Patch" -value $v.Build

And in the sql execution step, I tried calling the variable $OctopusParameters["Octopus.Action[StepName].Output.Major"] within the sql query but it doesn't get substituted. Code:

Update VersionTable SET Version='$OctopusParameters["Octopus.Action[StepName].Output.Major"]'

It just inserts the string $OctopusParameters["Octopus.Action[StepName].Output.Major"] into the system.

What have I done wrong please? Is there an easier way to do this plesae?

Thank you in advance

  1. Support Staff 1 Posted by Daniel Fischer on 23 Feb, 2018 03:54 AM

    Daniel Fischer's Avatar

    Hi Yvenchka,

    Thanks for getting in touch! I'm sorry for the delay in getting back to you! I have just tested this on my server and it looks like it work fine if you use the following in your query.

    Update VersionTable SET Version='#{Octopus.Action[StepName].Output.Major}'

    Octopus is able to substitute an Octopus variable denoted by #{ } in the SQL query whilst we can not evaluate a PowerShell variable there. So the fix is to reference your output variable with the Octopus syntax so we can correctly substitute.

    Let me know if this helps or if you have any further questions. :)

    Best regards,

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


? 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