How to set variables from powershell so that subtitle variables in files will work

we are setting up dynamic branches and need to update some files (config and js) with URL’s as well as database names, etc when a new branch is created. We started with creating variables in the project and using

Set-OctopusVariable -name "myUrl" -value $myUrlVariable

This doesn’t seem to work, it will only use the value of the initially setup variable at project level.

Are output variables from actions different to variables at the project level?

Is it possible to set project level variables from an action (powershell) level?

Is it possible to use action level variables in the “subtitle variables in files” action?

Is there another way to dynamically set variables and use the subtitle feature?

Regards

Jon

Hi Jon,

Thank for getting in touch and great question. Unfortunately, it’s not possible to set project variables during a deployment. Octopus snapshots a project’s deployment process, variables etc when creating a release so the that release can be deployed reliably over and over and over. If a project’s variables changed during a deployment, we wouldn’t be able to gaurantee that a release could be deploy to different environments reliably. That said, output variables are the solution for dynamic variables. They can be created, modified and retrieved during a deployment. Our output variables page is a great reference for this. http://docs.octopusdeploy.com/display/OD/Output+variables

I’ll answer your specific questions as well.

  • Are output variables from actions different to variables at the project level?
    Yes, project variables are designed to capture configuration items that change as you deploy a project through environments. They can be scoped to environments, machines etc and are static throughout a deployment. Output variables are their dynamic counterpart and can be created/modified and retrieved through a deployment.

  • Is it possible to set project level variables from an action (powershell) level?
    No.

  • Is it possible to use action level variables in the “subtitle variables in files” action?
    Yes. If you set output variables, you can use them in the subsitute variables in files feature using the variable binding syntax. i.e. #{Octopus.Action[StepA].Output.TestResult}

  • Is there another way to dynamically set variables and use the subtitle feature?
    Not out of the box. You could always script a solution yourself but it’s probably easier/faster to take advantage of output variables and the substitute in files features.

Hope this helps!

Thanks

Rob

Hi Rob,

Thank you for your feedback.

{Octopus.Action[StepA].Output.TestResult}

This looks like the way I will attack it.

Thanks