How to get the Package number on fly while deploying using System Variables

Hi Team,

I am working on a task where while deploying if release version number doesn’t match with the package number then the deployment should fail.

I am using octopus system variables “$OctopusParameters[“Octopus.Release.Number”]” to get the release number and “$OctopusParameters[“Octopus.Action.Package[Version-Number].PackageVersion”]” to get the package version number being deployed.

But the variable “$OctopusParameters[“Octopus.Action.Package[Version-Number].PackageVersion”]” is not able to resolve to actual value, instead it gives a null value.

in the above attached image i have even given the referenced package, and have wriiten a powershell script to print the values.

it can be seen that in the above image the package number is null value while release number has resolved with actual value.

Can you please help me out with this, so that i can get the Package number being deployed.

NOTE: WE ARE DEPLOYING MULTIPLE PACKAGES (all with same package number) IN A SINGLE APPLICATION, BUT I HAVE GIVEN ONLY ONE PACKAGE FOR REFERRED PACKAGE AS SEEN IN THE ABOVE IMAGE
I HAVE EVEN TRIED USING “$OctopusParameters[“Octopus.Action.Package.PackageVersion”]” VARIABLE, BUT THIS ALSO IS NOT ABLE TO RESOLVE THE ACTUAL VALUE

this is the powershell script which i am using :

$packagenumber=$OctopusParameters[“Octopus.Action.Package[Version-Number].PackageVersion”]
Write-Output “Package Number: $packagenumber”
$releasenumber=$OctopusParameters[“Octopus.Release.Number”]
Write-Output “Release Number: $releasenumber”.

Can you please help me out with this, or is there any better approach for getting the package number being deployed.

It would be of great help if a solution is provided for this.

Thanks,
Shaik Sadiq

Hi Shaik Sadiq,

Thanks for getting in touch! I appreciate you supplying lots of information to help me better understand your scenario!

I believe the issue is coming from the variable name you’re using - $OctopusParameters[“Octopus.Action.Package[Version-Number].PackageVersion”]. You’ll need to use the indexer notation on the Action to target the variable that was set on the specific step that deployed the package. I think the following tweak in your PowerShell script should give you the behavior you’re after (replacing StepName with the name of the step that deploys the package). :slight_smile:

$packagenumber=$OctopusParameters[“Octopus.Action[StepName].PackageVersion”]
Write-Output “Package Number: $packagenumber”
$releasenumber=$OctopusParameters[“Octopus.Release.Number”]
Write-Output “Release Number: $releasenumber”.

Let me know how you go or if you have any further questions!

Best regards,

Kenny

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.