Use Octopus 3.2 variables in Powershell script

Hello!

I want to use Octopus variables in my Powershell script (Not to hardcore it in the code).
Is it any way to do it in Octopus 3.2? (passing parameters in possible from 3.3)

Thanks for your advice.

Hi @AnastasiiaMonika,

Thanks for getting in touch! Octopus 3.2 should support variable substitution in your PowerShell scripts both inside Octopus, and inside .ps1 files in your package.

If the variable you want to evaluate is inside of a file in your package, then you can use our Substitute Variables in Files feature. As you are on a fairly old version of Octopus, the steps in the documentation along with the screenshots will be a bit different. However, the concept is the same.

  1. Create a variable in your project. (Or use a system variable)
  2. Reference the variable name in the script encapsulated with #{} like this: #{Variable.Name}
  3. Enable the Substitute Variables in Files feature
  4. Point towards the file which contains the variable you wish to evaluate.

If you use a script inside of Octopus, the idea is the same without using the Substitute Variables in Files feature. Simply create the Variable, and reference it with the #{} syntax.

The first two sections in this documentation page cover the above topic of replacing variables inside of scripts, and inside of Octopus.

Let me know if this helps, or if you have any further questions.

Best regards,
Daniel

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.