How to force a release to use the same version from all the packages

Hello,

We have a deployment that has 3 Steps:

  • DB script execution
  • Backend deployment to K8s
  • Frontend deployment to k8s

We have a pipeline that generates the 3 artifacts at the same time with the same version (we use the git short commit hash as the version of the package). We already have those as external feeds.

At the moment, developers can create a release and eventually select different package versions from every component:

Is it possible to force the developers to use the same version for all three packages?

I was thinking about getting the selected version in the first package (from Octopus Deploy System Variables) and then explicitly defining that in the next steps when selecting the packages. Something like this:

But I’m not sure if that’s even possible.

What would be the recommended way to achieve this?

Thanks!

Cheers,
Nicolás Spencer

Hi Nicolás,

Specifying the version using a variable on the Package ID field won’t work as it’s expecting just the Package ID. The version is selected at release creation time.

You could have your pipeline create the Octopus release as well and specify each package version which your developers could then just promote the release as-needed.

From there you could either remove developers access to create releases or use a script step at the beginning of the process to check and verify the versions are all the same before continuing. You could add more business rules here too, like if you wanted to allow it to happen but with interrupting the deployment process first to verify.

I hope this helps!
Mark

Hi @mark.reeder thank you very much for your answer.

We will go for the steps that validate that every package has the same version and in the future probably do something more sophisticated.

Kind Regards!
Nicolás

Hi @mark.reeder,

I was working on the logic, but I can’t find the way to get the versions from the Packages. I was following the documentation on how to get System Variables and it says I can select a particular package by indexing on the package ID, so this is what I am doing:

#!/bin/bash

SQL_PKG_VERSION=$(get_octopusvariable "Octopus.Release.Package[continuous-improvement:db-scripts].Version")
API_PKG_VERSION=$(get_octopusvariable "Octopus.Release.Package[continuous-improvement-api].Version")
CLIENT_PKG_VERSION=$(get_octopusvariable "Octopus.Release.Package[continuous-improvement-client].Version")

echo "-------------------------------"
echo $SQL_PKG_VERSION
echo $API_PKG_VERSION
echo $CLIENT_PKG_VERSION
echo "-------------------------------"

Where:
continuous-improvement:db-scripts
continuous-improvement-api
continuous-improvement-client

Are the Package IDs selected in the Release:

But the variables are not getting populated:

Any hint of what I might be doing wrong?

Thanks!

Cheers,
Nicolás

Hi Nicolás,

The Octopus.Release.Package variable is only available for use in the project release notes section. This is called out in that blue info box for the variable, but I’d agree we could delineate this better in the document.

The Octopus.Release.Package and Octopus.Release.Builds variables:
is only available to be used by the project release notes, it is not accessible from the project deployment steps.

The variable you’d want to use is under the Action heading. So give Octopus.Action.Package.PackageVersion a try. In your case the relevent part of your script would look more like:

SQL_PKG_VERSION=$(get_octopusvariable "Octopus.Action[continuous-improvement:db-scripts].Package.PackageVersion")
API_PKG_VERSION=$(get_octopusvariable "Octopus.Action[continuous-improvement-api].Package.PackageVersion")
CLIENT_PKG_VERSION=$(get_octopusvariable "Octopus.Action[continuous-improvement-client].Package.PackageVersion")

I hope this helps!

Thanks,
Mark

Hi @mark.reeder thank you for your answer. After I wrote the question I realized about the release notes section.

Using:

ACTION_NAME=$(get_octopusvariable "Octopus.Action.Name")

Returns the name of the step which is executing the script so I guess “Action” refers to the name of the Step and we are indexing by the name of the package.
What finally ended up working for us (partially) is indexing the Action by the Step Name and the Package by the Package Id, like this:

SQL_PKG_VERSION=$(get_octopusvariable "Octopus.Action[Execute SQL Script Files].Package[continuous-improvement:db-scripts].PackageVersion")
API_PKG_VERSION=$(get_octopusvariable "Octopus.Action[Deploy Continuous Improvement API].Package[continuous-improvement-api].PackageVersion")
CLIENT_PKG_VERSION=$(get_octopusvariable "Octopus.Action[Deploy Continuous Improvement Client].Package[continuous-improvement-client].PackageVersion")

And when I echo the variables to see it in the logs I get this:

So now we are able to get the package versions but not from the Step that comes from a community template (“SQL - Execute SQL Files”)

Does

SQL_PKG_VERSION=$(get_octopusvariable "Octopus.Action[continuous-improvement:db-scripts].Package.PackageVersion")

Not work when using a community template?

How can I get the Version from the package used in that step?

Thanks!

Kind Regards,
Nicolás Spencer

Hi Nicolás,

Yeah, with a step template it is a bit different. The Package is also indexable so this should work for you for that SQL community step template:

SQL_PKG_VERSION=$(get_octopusvariable "Octopus.Action[Execute SQL Script Files].Package[template.Package].PackageVersion")

I discovered this by using the OctopusPrintVariables and OctopusPrintEvaluatedVariables system variables for my debugging puposes.

Give this a try and let me know if you still run into issues.

Thanks,
Mark

Hi @mark.reeder, it works :smiley:

Thank you very much for your answer!

Best,
Nicolás Spencer

1 Like