Run Powershell script stored in variable

Hi!

How is it possible to store some common script in variable and then run reference it in Deployment script section of deploy step?
E.g. I have created variable (in shared variable set) named CopyAssetsScript and it has this value:
copy assets\robots.#{SolutionConfiguration}.txt robots.txt

I would like this script to be taken from variable in “Deployment script” field and executed on deploy (as if it would be written there directly). I was trying saving this:
$CopyAssetsScript

but after i click save button and then open edit step, it’s gone and the “Deployment script” field is empty again.

I’m using Octopus v3.1.1.

Thank You!

Hi,

Thanks for reaching out. The reason why the variable is not being saved is because of this bug: https://github.com/OctopusDeploy/Issues/issues/1974 . Check my comment on it for a workaround.

Hope that helps!

Dalmiro

Hi Dalmiro!

Thanks for reply. That workaround did work except that scripts which are stored in variable actually are not run. They are just logged out in deploy log and that’s it.
Do you know if there is way to store entire script in variable and execute it just referencing that variable?

For example it would be really convenient for me to store in a single variable (in shared variable set) common script like this:

Remove-Item connectionStrings.*.config
Remove-Item web.*.config

Hi!

Just found that there is invoke-expression command which does exactly what i need:

invoke-expression $RemoveTransformationsScript