Windows Service Name and substitutions

Hi

Trying to push package as a Windows Service and would like to suffix servicename with the name of my environment, like this

ServiceName
My.Microservice.(#{Octopus.Environment.Name})

DisplayName
My Microservice (#{Octopus.Environment.Name})

The environment is named “TestInstance01” and I would expect it to produce
My.Microservice.TestInstance01 as service name. and “My Microservice (TestInstance01)” as Displayname

It doesn’t. It’s My.Microservice.Default and “My Microservice (Default)”.

Looking through variables preview (System) I see:
Octopus.Action[Install as a service].WindowsService.ServiceName =
My.Microservice.TestInstance01, so it looks like it should be ok, just not in the actual deploy

I made sure to update all variables, and I have tried recreating the “Windows Service” step - same result.

Hi @mpr,

Thanks for getting in touch!

It does look like this is configured correctly, and the test I just ran does successfully replace the values.

It may be worth adding a project variable named OctopusPrintEvaluatedVariables with a value of true. Then if you check the full deployment log it will output all variables including the system ones such as Octopus.Environment.Name.

It would be interesting to see what the results of this are.

Regards,
Paul

This is the output

Using Calamari 7.1.9

[Octopus.Release.Channel.Name] = ‘Default’

[Octopus.Space.Name] = ‘Default’

[Octopus.Action.WindowsService.CreateOrUpdateService] = ‘True’ May 18th 2020 15:04:16
[Octopus.Action.WindowsService.Description] = ‘My microservice (Default)’ May 18th 2020 15:04:16
[Octopus.Action.WindowsService.DesiredStatus] = ‘Default’ May 18th 2020 15:04:16
[Octopus.Action.WindowsService.DisplayName] = ‘My Microservice (Default)’ May 18th 2020 15:04:16
[Octopus.Action.WindowsService.ExecutablePath] = ‘bin\MyService.exe’ May 18th 2020 15:04:16
[Octopus.Action.WindowsService.ServiceAccount] = ‘NT Authority\NetworkService’ May 18th 2020 15:04:16
[Octopus.Action.WindowsService.ServiceName] = ‘My.Microservice.Default’ May 18th 2020 15:04:16
[Octopus.Action.WindowsService.StartMode] = ‘auto’

There should be an entry for [Octopus.Environment.Name] in the log too.

e.g.

14:09:51 Verbose | [Octopus.Environment.Name] = ‘Dev’
14:09:51 Verbose | [Octopus.Action.WindowsService.DisplayName] = ‘My.Microservice.(Dev)’

[Octopus.Environment.Name] = ‘TestInstance01’

btw. Octopus server is 2019.9.1

Hmm. weird…

So, yesterday trying to figure stuff out, I put in a Step : “Install My Service”. Then in order to start fresh I deleted said step and created a new one “Install as a service”. But the log from the build says.

[Octopus.Action[Install My Service].WindowsService.Description] = ‘My microservice (Default)’
where I would expect
[Octopus.Action[Install as a service].WindowsService.Description] = ‘My microservice (TestInstance01)’

Interestingly - I initially experimented with Service Name = "My.Service.#{Octopus.Channel.Name} which is now “default”.

So maybe it’s a matter of the Release remembering the former Process steps?

That does make more sense, as Octopus.Channel.Name does explain where the ‘default’ value is coming from.
When a release is created it snapshots the current process step, if a change is then made to those process steps a new release must be created for them to be applied.

So, if your service process is currently set to Service Name = "My.Service.#{Octopus.Environment.Name} I would recommend creating a new release and re-trying the deploy.

Wil do.

Since it is able to monitor changes to Variables and update the snapshot for those, I would suggest a new feature: Octopus should be able to do the same for Process Steps :wink:

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.