Output variables and project variables - which should take precedence?

Hey team,

We are trying to set up a pipeline where we have some default project variable values that could be overwritten/updated by steps within the pipeline, but having some issues with variable precedence between project vars and output vars.

Basically, we want to have a project variable, called say ‘KeyName’, and have its default value be ‘I am a key’. During one of the build steps, logic may determine that we want to update this variable value to be ‘I am not a key’ so that subsequent build steps see the value ‘I am not a key’ rather than the default value.

We have tried setting the project variable name to the same name as the output variable from the step updating the value, i.e. our project variable key is ‘Octopus.Action[Step One].Output.KeyName’, so that when we run

Set-OctopusVariable -name “KeyName” -value “I am not a key”

from the build step ‘Step One’, we are updating the same value. However the value seems to be overwitten by the default value in the project variables within subsequent build steps.

Any ideas as to how to get around this cleanly?



It looks like output vars and project vars get merged at the beginning of each step, with project vars taking precedence, is there are reason for this? Could you change the order that these get merged to allow for setting default output variable values in the project variables?

Hi James,

Thanks for getting in touch! The project variables and the output variables, whilst listed together in the logs, are actually separate entities. The output variables are step specific variables, which are unable to affect the project variables. Setting and modifying variable values during the deployment is limited to output variables. Without knowing exactly what logic you want your steps to check, I can only give you a rough idea of whats available.

You are able to use our variable substitution syntax to do logic within the project variables. This can also be used with the Output variables. So you could potentially limit your logic and substitution entirely to either project or output variables. https://octopus.com/docs/reference/variable-substitution-syntax

If you you still need a hand getting this working, some more specifics on your requirements would help me give you some more precise options. :slight_smile:

Let me know how you go.

Best regards,