I am trying to install and start a windows service in an azure vm but the start step is failing.
Here are the pipeline tasks:
- task: jabbera.windows-service-release-tasks.install-topshelf-service-task.InstallTopshelfService@8
displayName: 'Install a Topshelf Service'
inputs:
TopshelfExePaths: '${{ parameters.svcDir}}${{ parameters.svcAssemblyName }}.exe'
specialUser: localsystem
ServiceName: '${{ parameters.svcName}}'
StartupType: autostart
KillMmcTaskManager: true
deploymentGroup: true
- task: jabbera.windows-service-release-tasks.start-windows-service-task.StartWindowsService@8
displayName: 'Start Windows Service'
inputs:
ServiceNames: '${{ parameters.svcName}}'
deploymentGroup: true
Start fails with the following error:
##[error]Unable to find type [VstsTaskSdk.TerminationException].
2024-05-08T09:54:34.2331237Z ##[error]Exit code 1 returned from process: file name ‘C:WindowsSystem32WindowsPowerShellv1.0powershell.exe’, arguments ‘-NoLogo -Sta -NoProfile -Non***nteractive -ExecutionPolicy Unrestricted -Command “. ([scriptblock]::Create(‘if ([Console]::***nputEncoding -is [Text.UTF8Encoding] -and [Console]::***nputEncoding.GetPreamble().Length -ne 0) { [Console]::nputEncoding = New-Object Text.UTF8Encoding $false } if (!$PSHOME) { $null = Get-tem -LiteralPath ”variable:PSHOME” } else { ***mport-Module -Name ([System.***O.Path]::Combine($PSHOME, ”ModulesMicrosoft.PowerShell.ManagementMicrosoft.PowerShell.Management.psd1”)) ; ***mport-Module -Name ([System.***O.Path]::Combine($PSHOME, ”ModulesMicrosoft.PowerShell.UtilityMicrosoft.PowerShell.Utility.psd1”)) }’)) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; mport-Module -Name ‘C:azagentA1_work_tasksStartWindowsService_bf65dd9d-18cb-40d9-9254-f3ac527428ef8.0.0ps_modulesVstsTaskSdkVstsTaskSdk.psd1’ -ArgumentList @{ Nonnteractive = $true } -ErrorAction Stop ; $VerbosePreference = ‘SilentlyContinue’ ; $DebugPreference = ‘SilentlyContinue’ ; ***nvoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create(‘. ”C:azagentA1_work_tasksStartWindowsService_bf65dd9d-18cb-40d9-9254-f3ac527428ef8.0.0StartWindowsService.ps1”’))”‘.
Github link: https://github.com/jabbera/my-vsts-tasks
I tried replacing it with powershell task:
- powershell: |
$serviceName = '${{ parameters.serviceName }}'
$serviceStatus = Get-Service -Name $serviceName
if ($serviceStatus.Status -eq 'Running') {
Write-Host "Service '$serviceName' is already running."
} elseif ($serviceStatus.Status -eq 'Stopped') {
Start-Service -Name $serviceName
Write-Host "Service '$serviceName' started successfully."
} else {
Write-Host "Service '$serviceName' is in an unexpected state: $($serviceStatus.Status)"
}
condition: ${{ parameters.startService }}
displayName: 'Start Windows Service'
But this failed:
Start-Service : Service ‘MyService’ cannot be started due to the following error: Cannot
2024-05-08T14:25:47.7248406Z start service MyService on computer ‘.’.
2024-05-08T14:25:47.7250339Z At C:azagentA1_work_temp5d2155f7-3687-4ce8-ab8e-fbf42272de9d.ps1:9 char:5
2024-05-08T14:25:47.7252117Z + Start-Service -Name $serviceName
2024-05-08T14:25:47.7253589Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2024-05-08T14:25:47.7255675Z + Categorynfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service],
2024-05-08T14:25:47.7257458Z ServiceCommandException
2024-05-08T14:25:47.7259190Z + FullyQualifiedErrord : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand
2024-05-08T14:25:47.7260730Z
2024-05-08T14:25:47.7300363Z ##[error]PowerShell exited with code ‘1’.
2024-05-08T14:25:47.7904871Z ##[section]Finishing: Start Windows Service: MyService