gha: windows: skip "Stop OpenTelemetry Collector" if it wasn't started

If setup failed or was skipped, this produced an error;

    Run (Stop-Service -DisplayName "OpenTelemetry Collector" -PassThru).WaitForStatus('Stopped', (New-TimeSpan -Seconds 30))
    Stop-Service: D:\a\_temp\f0230cca-e5e4-4a0b-9fe2-0d0a6a5bc60e.ps1:2
    Line |
       2 |  (Stop-Service -DisplayName "OpenTelemetry Collector" -PassThru).WaitF …
         |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Cannot find any service with display name 'OpenTelemetry Collector'.
    Error: Process completed with exit code 1.

Skip this step if we skipped "Set up OpenTelemetry Collector", and ignore situations
where the service could not be found for other reasons.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2026-06-11 09:29:29 +02:00
parent 0d0a1933c5
commit 15acfdfc71

View File

@@ -329,6 +329,7 @@ jobs:
cache: false
-
name: Set up OpenTelemetry Collector
id: setup-otel
run: |
New-Item -ItemType Directory -Force -Path bundles -ErrorAction Continue
Start-Process "msiexec" -ArgumentList "/i",
@@ -548,9 +549,12 @@ jobs:
Tee-Object -file ".\bundles\daemon.log"
-
name: Stop OpenTelemetry Collector
if: always()
if: ${{ always() && steps.setup-otel.outcome != 'skipped' }}
run: |
(Stop-Service -DisplayName "OpenTelemetry Collector" -PassThru).WaitForStatus('Stopped', (New-TimeSpan -Seconds 30))
$svc = Get-Service -DisplayName "OpenTelemetry Collector" -ErrorAction SilentlyContinue
if ($svc -and $svc.Status -ne "Stopped") {
($svc | Stop-Service -PassThru).WaitForStatus("Stopped", (New-TimeSpan -Seconds 30))
}
-
name: Upload reports
if: always()