We are running powershell DSC through Octopus and running into an issue. As it is now we have a zip that contains the ps1 file that is our main DSC. This contains things like creating folders, setting up websites, creating app pools, and also has custom scripts in it to set app pool user names. The issue is that we have variables in those nested custom scripts and they aren’t getting replaced since I guess they aren’t necessarily run at the time the mof file is being generated.
One potential way around this is to change the process step from “deploying a powershell script” to “deploy a nuget package” and then change all the variables we have set as $octopusparameters[“variable”] to #{variable} and then just replace them all before it is even run. While this does seem to be a solution, we were wondering if there is another way of doing this and keeping the “deploy a powershell script” step?
You are correct in that the “Run a Script” step does not perform variable replacements. This is only available on the “Deploy a package” step.
Can you explain why you don’t want to use the “Deploy a package” step? It will happily deploy a zip file, replace the variables, and then you can run the DSC from there?
Actually, the more I think about it, the more I think I need more information. If you are referencing variables in your “Run a Script” step via $OctopusParameters[’’], then they should all be available?
Can you share more details about the process and how you are using the variables and where they are not working? Screenshots will probably help a lot here.
We actually did switch to deploy a package and change our variable syntax so we are able to do the replacement. We just needed to deploy a powershell script so that is why we chose that step.
You are right in that the $OctopusParameters were available, but with DSC since we had nested scripts that don’t run until after the MOF file is generated those ones were not.
So solution is, if using DSC with nested scripts, then using “Deploy a package” step is a must for variable replacement, that way the variables all get replaced before the script is even run.