I’ve tried $serverName | Write-Host and $OctopusParameters[“serverName”] | Write-Host in my PostDeploy.ps1 file and it’s not returning anything.
When I do the same on executing a powershell script as a step it does return a value
Also when I test PostDeploy.ps1 by running Tentacle.exe run-script -v serverName=“test” -f PostDeploy.ps1 it does return a value.
The same variable also works for a XML Transformation for the appsettings.config file.
What am I missing to get variables to work with PostDeploy.ps1 ?
Have you double-checked that your Variables in the Octopus UI are properly set for the context in which your PostDeploy.ps1 is executing? For example: Environment, Role, Machine, etc.
That could do it.
Yes the Environment, Role, and Machine are properly set. The variable works for transforming *.config files. I’m also assuming that PostDeploy.ps1 runs during the same step (Deploy) as when it transforms the *.config files
Can you attach a screenshot of your variables page and the deployment log (or email them to email@example.com)?
The project that I was testing the variables on was just a sandbox project I have setup in Octopus. Once I added the variable and PostDeploy.ps1 to a real project the variable started working.
Thanks for the follow up.
We are having exactly the same issue. I declared two variables ServiceName and OctopusPackageDirectoryPath to be used by PreDeploy.ps1 and Deploy.ps1. It is a windows service which will be deployed to tow environments and will have a different name and path for each environment. Unfortunately, the powershell script doesn’t read those variables and therefore it installed the service with default name “OctoService”. Is there something we are missing?
Files are attached.
Deploy.ps1 (1 KB)
PreDeploy.ps1 (439 Bytes)