When writing a step as a PowerShell script, I have access to variables through the $OctopusParameters dictionary. This dictionary contains all variables declared on the project along with variables declared in any included variable set and a bunch of system variables.
Is there any way to a dictionary with only the variables declared directly on the project? Use case: I need to build a JSON file containing all application configuration as part of the deployment process.
Thanks for reaching out! There’s not direct way from the deployment to only get the project variables, but you can get them using the Octopus API. I’m gonna show you 2 methods to do it:
A) Do a GET to the project variable set url. The URL format looks like this
Then you can use $VariableSet.Variables to create your json
The advantage of this method over (A) is that this one returns the actual names of the resources listed on the scopes like Production and Computer1 instead of Environments-1 and machines-2 which wont be that helpful on your JSON
The disadvantage is that you’re gonna have to install the module on the machine that will be using the cmdlet.
Please keep in mind that this is an open source project, so all questions about it must be done on project’s site