Is it possible to update OctopusParameters from within PreDeploy.ps1?

Hi,

Background: We really need to have some kind of environment variables in order to simplify our product variable configurations.
The reason for this is that we do have a couple of values which have to be the same for a set of services/applications but which vary from environment to environment.
Eg. IIS.SubSiteName, STS.IssuerThumbprint, STS.IssuerName, AppsHostName, ProxyHostName, ServicesHostName (STS = Security Token Service)

In order to circumvent octopus’s lack of environment variables we do plan to have a special project which places a file under Octopus/Applications/ containing the values of all those common variables. This file is going to be read from the PreDeploy.ps1 file of all our projects and the values are going to be written into $OctopusParameters.
This way we could refer to those common values from variable definition like that: 'SECURITY.EnableSTS = IssuerThumbprint=#{STS.IssuerThumbprint};Domain=#{ServicesHostName};Realm=…'
We do already use variables like that to control the parameters used by parametric transformations (ctt.codeplex.com). (We do have implemented our own version of variable value expansion)
This way the pure occurrence of a variable like SECURITY.EnableSTS triggers a parametric transformation in PreDeploy.ps1 which inserts/replaces all sections/values in the web.config file required in order to enable STS based authentication/authorization.

But back to the original question: In order to let Octopus update the correct IIS website, we would like to be able to make Octopus use our (environment specific) value of IIS.SubSiteName for a deploy step like that: Site/virtual directory: #{IIS.SiteName}#{IIS.SubSiteName}/#{IIS.AppName}.
Writing the value back to $OctopusParameters[‘IIS.SubSiteName’] from within PreDeploy.ps1 is unfortunately not having any effect.
So the question is, is there another way to communicate updated/new variable values back to the tentacle process?
Or much better: Are there any actual plans on supporting environment/machine variables in Octopus?

Thanks,
Matthias

Hi Matthias,

You can use the commandlet “Set-OctopusVariable” from within your PowerShell script to set a variable that will be available within Tentacle.

Paul

Hi Paul,

Using the “Set-OctopusVariable” commandlet does update the variables but unfortunately these changes are ignored by the tentacle if it comes to updating the website. (see attached log file)

I have been updating the values for IIS.SiteName, IIS.SubSiteName and IIS.AppName in the PreDeploy.ps1 file of the attached package:

DEBUG [PreDeploy Script] Script: C:\Octopus\Applications\GeminiCI\OctopusEnvVarTest\1.0.5\PreDeploy.ps1
INFO [PreDeploy Script] [Set-OctopusVariable] IIS.SiteName=PreDeploy.IIS.SiteName
INFO [PreDeploy Script] [Set-OctopusVariable] IIS.SubSiteName=PreDeploy.IIS.SubSiteName
INFO [PreDeploy Script] [Set-OctopusVariable] IIS.AppName=PreDeploy.IIS.AppName

But the tentacle is not using these values for updating the web site and therefore fails with the following exception:

Could not find an IIS website or virtual directory named ‘#{IIS.SiteName}#{IIS.SubSiteName}/#{IIS.AppName}’ on the local machine.

Is there a way to make the tentacle update the correct website according to the values updated in PreDepoy.ps1?

Tanks,
Matthias

OctopusEnvVarTest.1.0.5.nupkg (3 KB)

OctopusEnvVarTest.log (23 KB)

Thanks Matthias, I guess there’s a bug here - we should re-evaluate variables after they change.

In the mean time, you can use:

Set-OctopusVariable -Name “OctopusWebSiteName” -value “Some value”

The OctopusWebSiteName variable is the one that tells Octopus which IIS path to update.

Paul