Deploy IIS Step: app pool registration script does not substitute #{variables}

I’m trying to create an IIS deployment step, where Application pool name is generated as a combination of a constant string and #{Octopus.Release.CurrentForEnvironment.Name} variable data.
While it works for ‘Web Site name’ field, it fails for ‘Application Pool name’. Looks like variable substitution does not work for this property.

Octopus version is 3.16.3
Tentacle version is 3.15.6

Log output:
Application pool “#{Octopus.Release.CurrentForEnvironment.Name}.tolerance.api.local” does not exist, creating…

SemaphoreInstance Global\Octopus-IIS-Metabase released

New-Item : Invalid application pool name
At E:\Octopus\Applications\Test\Seek4Cars.API.Tolerance.Service\\Octo

pus.Features.IISWebSite_BeforePostDeploy.ps1:195 char:4

  •         New-Item $appPoolPath -confirm:$false
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidData: (:slight_smile: [New-Item], COMException

  • FullyQualifiedErrorId : Invalid application pool name


Deleting ‘E:\Octopus\Applications\Test\Seek4Cars.API.Tolerance.Service\\Octopus.Features.IISWebSite_BeforePostDeploy.ps1’

Script ‘E:\Octopus\Applications\Test\Seek4Cars.API.Tolerance.Service\\Octopus.Features.IISWebSite_BeforePostDeploy.ps1’ returned non-zero exit code: 1

Running rollback conventions…

Adding journal entry:

Script ‘E:\Octopus\Applications\Test\Seek4Cars.API.Tolerance.Service\\Octopus.Features.IISWebSite_BeforePostDeploy.ps1’ returned non-zero exit code: 1

Updating manifest with output variables

Updating manifest with action evaluated variables

Planning retention policy

The remote script failed with exit code 1

at Octopus.Worker.Scripting.ScriptResult.EnsureSuccessful()

at Octopus.Server.Orchestration.Deploy.Package.PackageActionHandler.Execute(ActionCommand command, Machine machine)

at Octopus.Server.Orchestration.Deploy.DeploymentTaskController.<>c__DisplayClass29_0.b__0()

at Octopus.Server.Orchestration.Deploy.DeploymentTaskController.ExecuteWithTransientErrorDetection(Action action, Machine machine)

at Octopus.Server.Orchestration.Deploy.DeploymentTaskController.ExecuteActionAndInitLoggingContext(PlannedStep step, Machine machine, PlannedAction action)

Deploy IIS on Localhost

Ok, it looks like none of step properties support #{variable} substitution.
Could someone suggest. how I can update some of IIS deployment properties according to current environment?

Ok, I’ve finished with lots-of-variables-for-each-environment solution.


Thanks for getting in touch! I had a look into this and was unable to find reference to the variable #{Octopus.Release.CurrentForEnvironment.Name}. There were similar variables:

#{Octopus.Release.CurrentForEnvironment.Id} This returns the ID like release-123
#{Octopus.Release.CurrentForEnvironment.Number} This returns the release number like 1.4.2

Using #{Octopus.Release.CurrentForEnvironment.Name} works for the site name as it will evaluate as a string. However, when using it as an application pool, you will get this error. This is because the variable is not actually evaluating. It is simply trying to use the variable name un-evaluated as a string.

What are you trying to have Octopus evaluate #{Octopus.Release.CurrentForEnvironment.Name} to? If you want the name of the environment that you are deploying to, then you can use #{Octopus.Environment.Name}.

The solution here is as you have said, either create a bunch of different variable that can be manually set. Or if you want the environment display name, use the above environment name variable.

Let me know if I have missed something here or if you have any further questions.

Best regards,