Can Output variables from PreDeploy be used in the deployment?

I am looking at various ways to assign port numbers to an IIS deployment. I know I can do this with a step prior to the deployment step, but I’m wondering if there is a way to set output variables in PreDeploy to be used by the deployment. I haven’t been able to get it to work, but I’m not sure if it’s an issue with what I’m doing, or if it’s not possible. Can you update the variables used by a deployment step within the PreDeploy script?

Thanks,
Erick

Hi Erick,

Thanks for getting in touch! You can define variables in the PreDeploy to then be used by the PostDeploy no problems.
Setting the variablen in your PreDeploy: Set-OctopusVariable -name "TestResult" -value "Passed"
Then retrieving it via your PostDeploy: http://docs.octopus.com/display/OD/Custom+scripts#Customscripts-VariablesinPowerShellscripts

You cannot during deployment update project level variables, but you can overwrite them in the context of the step.

Hope that helps!
Vanessa

Thanks Vanessa.

I want to run code in PreDeploy that picks an open port for an IIS WebSite. From my understanding, I wouldn’t be able to use the port from the code in the IIS setup (via the Octopus Step configured in the UI). Is that correct?

I know I can have a separate step to find an open port, but I’m trying to keep everything in a single package.

Thanks,
Erick

Hi Erick,

I can’t see why you couldn’t set a value for a variable in the predeploy that the IIS feature is set to use later in the step. Have you tried this? Do you need some pointers? (I wanted to confirm this myself but have run out of daylight hours)

Vanessa

Hey Vanessa,

I haven’t tried it. I found a couple of posts[1] talking about how to do it (I can only find one at the moment). They both had the port assignment being done in an explicit script step prior to the deployment step, so I assumed that was required. If I can update a value in the PreDeploy script, that makes life so much simpler!

Thanks,
Erick

[1]
http://help.octopusdeploy.com/discussions/problems/23610-dynamic-creation-of-port-number-in-iis-bindings

Hi Erick,

From that other post, the only thing Octopus cannot do is pick the port, but if you do that in PreDeploy the rest can be done. Binding the variable for the port and then using it later.
Let me know if it behaves unexpectedly.

Vanessa