I want to compare/validate variables during deployment programmatically between two environments. For example when a deployment to pre-prod occured I plan to add custom script step to make sure all variables that are in scope and available to pre-prod are also available in PROD
I am not sure if my approach is correct - please suggest if there is a better way.
The closest resourse for quering the Octopus API for this purpose is this: https://github.com/OctopusDeploy/OctopusDeploy-Api/tree/master/Octopus.Client/PowerShell/Variables
However, I am not sure how to get a list of all variables available to the current deployment?
In addition, how can I get a list of all variables available for a deployment project in a environment?
Obviously what will be really good is if there is a “Variable Policy” feature in Octopus we could apply… For example if this variable is available in this environment it must be also be available in that environment etc.
Thanks for your help!
Thanks for getting in touch! I imagine there will be a way to validate variables in this way programmatically, however I didn’t have any luck finding examples online or in our API sample repo, unfortunately. I can think of a couple alternative options where hopefully one will be helpful and easier.
The variable preview feature allows you to see how all of your variables will evaluate before deploying. This is located in your web portal under [Project] > Variables > Preview tab where you can specify environments, targets, roles, etc. and show how the variables will evaluate on deployments that match the specified criteria. You can then compare the results between two environments beforehand.
You can also write all of the variables and what they evaluate into during deployment to your deployment log by enabling debugging variables. These variables aren’t enabled by default, as it increases the size of your task log and could slow down deployment time.
Your suggestion for a Variable Policy feature is interesting, and there’s an existing UserVoice item to “Support Required Variables”. Is this similar to what you’re after? Feel free to vote on it and comment on it about your use case.
I hope this helps! Don’t hesitate to reach out if you have any further questions or concerns.
thank you for your response, however I am stuck at the moment.
Is there any code sample how to preview the variables evaluations programmatically?
I guess if you are using this in the UI it should be possible for me to do it programmatically where I get the “preview” results for one target environment and compare against another target environment…
How could I do this please?
I want to compare the evaluated variable output for two different environments. If there is a better way to do that I would like to hear it
I also commented on the user voice suggestion about extending it to Variable Policy.
Another question I have is if I can enforce variable checks by using Common Variable Templates? I haven’t used them since we upgraded recently and it is new feature for me. From the documentation it is not clear if it is applicable only to Multi-tenant deployments?
Thanks for following up, and you’re very welcome! Unfortunately I haven’t been able to locate a sample script to preview the variable preview programmatically, however when checking the network traffic when performing this action (previewing for the Development environment), the GET request hits the URL at:
You can then add additional parameters to this endpoint to preview by channel, role, etc. with the same syntax:
I’d also be very interested to hear if you write out a script to retrieve these values. And feel free to add it up on our sample script repo!
Common Variable Templates are used to require variable values specific to each tenant, where the value won’t differ between the projects that they’re connected to. For example, contact details or an alias for each tenant. Variables within these Common Templates will display on the preview as well.
I hope this helps! Let me know how you go or if you have any further questions.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.