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?
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!
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.
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:
Are the Package IDs selected in the Release:
But the variables are not getting populated:
Any hint of what I might be doing wrong?
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.
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:
I hope this helps!
Hi @mark.reeder thank you for your answer. After I wrote the question I realized about the release notes section.
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”)
Not work when using a community template?
How can I get the Version from the package used in that step?
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
OctopusPrintEvaluatedVariables system variables for my debugging puposes.
Give this a try and let me know if you still run into issues.
Hi @mark.reeder, it works
Thank you very much for your answer!