Can I deploy a Windows service X number of times, and set the count depending on Environment?

michael.storry's Avatar


02 Jan, 2018 10:58 AM

I have a requirement whereby in Live environment, we deploy multiple instances of 'My Windows Service' in parallel (long story, but this is what I'm working with) to the same server.

In Preprod, we only need a single instance of 'My Windows Service', in order to test functionality. I know I can duplicate the Process steps, and set scope to Live only, which is one way of allowing my to deploy multiple services. However, this is not very flexible, and I would prefer a single process step, that applies across all environments, with a simple variable such as 'NumberOfServices'.

This would then allow me to specify how many instances of the service I need on a per-environment basis, with a simple variable change. I would then have some logic to set the Service Name and Service:
ServiceName = MyServiceNameX , where X is the count/index of the service being deployed.

Hope the above makes sense; any queries I'll do my best to clarify.

  1. Support Staff 1 Posted by Reece Walsh on 03 Jan, 2018 06:28 AM

    Reece Walsh's Avatar

    Hi Michael,

    Thanks for getting in touch,

    Instead of utilizing multiple steps that are scoped to a specific environment as you've highlighted, another solution could be to re-add the same deployment target multiple times (uniquely named), in doing this you can have a single deployment step that deploys to all duplicate targets in the environment, in your example this would deploy a windows service multiple times to the same machine, you can use target roles to control the number of services that are deployed.

    It's worthwhile to note, however, unlike multiple steps that can be executed in parallel this process would require each step be run individually which depending on the number of services to be installed could elongate the deployment process.

    We'll look into provisioning documentation for our support area regarding this additionally.

    If I've misunderstood in any way please let know, I hope this help! :)

    Kind Regards,


  2. 2 Posted by michael.storry on 05 Jan, 2018 11:47 AM

    michael.storry's Avatar

    Thanks Reece, that makes sense. However, unless I've misunderstood, I see a potential issue relating to how Windows services are installed.

    One of the variables we specify is 'ServiceName', i.e. the name of the Windows Service we are installing. This needs to be unique, otherwise we will simply be installing the Service, and then subsequently over-writing, unless I add some logic which appends a piece of information from the server role that we are installing to?

    E.g. need to ensure I am installing 3x Windows services, with Service names:

    Thanks, Michael

  3. 3 Posted by Tomas Polak on 05 Jan, 2018 02:48 PM

    Tomas Polak's Avatar

    Hi Michael,
    glad to see we're not the only ones deploying multiple instances of Windows services. We've 'overcome' the deficiency of the deployment step by creating our own outside Octopus. Reasoning was that this initially sounded like simple task, but then when you change the number of instances or you want to completely remove them or just reconfigure some of them, and we do need all that, we've realized the complexity requires dedicated app which does that for us. We do trigger it from Octopus of course.
    Also we've similar use cases for Scheduled tasks as well, again multiple schedules for several instances of same application, each with different specific configuration. So that we covered by this custom app as well.
    I know I am not helping you much, since I can't share company proprietary code, but would be keen to watch this question for updates from others, perhaps there's or will be out of the box solution one day I'd prefer to use or we can at least share ideas about the approach.
    Thank you.

  4. 4 Posted by michael.storry on 05 Jan, 2018 03:01 PM

    michael.storry's Avatar

    Hi Tomas

    Same here - glad to hear we're not the only ones with this scenario... Yes hopefully in future Octopus will have some sort of 'interpolation' logic built in, which will allow us to specify a 'count' of vars / services / whatever.


  5. Support Staff 5 Posted by Reece Walsh on 09 Jan, 2018 01:42 AM

    Reece Walsh's Avatar

    Hi Michael,

    Thanks for getting back to me regarding this,

    In order to accommodate unique service names, you would need to include multiple variable values that are scoped to the unique targets, as previously mentioned these targets represent the same physical target re-added with a unique name and port, if using the same port you would need to configure a rolling deployment in order to avoid a deadlock on server tasks.

    I've included a screenshot below of how this looks on a basic level, in this way you would be able to avoid the windows service from attempting to overwrite itself based on instance name.

    [Refer to Screenshot 1]

    I'd recommend having a read through the following blog post that covers variable specificity and complexity to understand how Octopus will prioritize variables.

    I hope this helps!, if I've misunderstood your concern please let me know :)

    Kind Regards,


Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac