Search code examples
azure-devops

Azure DevOps - deploy Window Service task


I have a pipeline set up with multiple deployment groups. On one of my deployment groups, the service gets installed on the C: drive. On the other, to a different location on the E: drive.

On a new deployment group I set up, the target destination is the source destination as is failing because the file already exists, or if I do a 'clean' install, I obviously get the 'file not found' error.

I examined the tasks and neither specify a target location. I also checked the environments, and there is nothing that points to a target location.

Here is the associated YAML:

steps:
- task: MDSolutions.WindowsServiceManagerWindowsServiceManager.WindowsServiceManager.WindowsServiceManager@4
  displayName: 'Deploy Windows Service'
  inputs:
    DeploymentType: DeploymentGroup
    ServiceName: My.Portal.Service
    ArtifactPath: '$(System.DefaultWorkingDirectory)/_Portal.UI/My.Portal.UI/winservice'
    TimeOut: 600

I verified the tasks are the same between the two deployment groups.

What am I missing?

Thank you


Solution

  • You need to use class release editor for the task with deployment group. if you use yaml for pipeline, it's running on the agent machine not deployment group machine.

    As mentioned in the doc:

    enter image description here

    You can follow below steps with the task:

    1. I have build pipeline to create the artifact of the service.exe as below, you can refer to the link about the build steps.

    enter image description here

    1. Consume the build artifact in the release pipeline. Add deployment group job to use the machine. enter image description here

    2. The WindowsServiceManager task will check if the service exists on the machine or not.

    Since my service file in zip, tried on my side, the task seems copied nothing to the installation path, which will cause service fail to start.

    To install the service and start it, you can extra the zip file to a folder, and specify installation path to the file, so that the service can start.

    enter image description here

    The result: enter image description here

    If the service already existed on the deployment machine before the pipeline, the task will automatically find the service file path, will not use installation path.

    enter image description here

    You can use clean install to clean the old files, and copy from extracted path as artifact path to get the service file. enter image description here

    enter image description here

    the service gets installed on the C: drive. On the other, to a different location on the E: drive.

    Hence, you can check if the service already exists on the agent before, as it could use original path.