From 3803d1673139004ca90af288c54aab21d3ec21b5 Mon Sep 17 00:00:00 2001 From: Scott Pouliot Date: Fri, 8 May 2026 21:44:51 -0400 Subject: [PATCH] Fix prod Jenkins pipeline: add tests, restart, and health check stage - Add Test stage (unit tests only) before migrations so bad code fails fast - Add az webapp restart after async deploy to ensure new code is loaded - Add Health Check stage that polls app for up to 3 minutes post-deploy - Restore xcopy of wwwroot (needed for linux-x64 publish on Windows) Co-Authored-By: Claude Sonnet 4.6 --- Jenkinsfile | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 8e23b31..07d9c8b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,6 +24,17 @@ pipeline { } } + stage('Test') { + steps { + bat 'dotnet test tests\\PowderCoating.UnitTests --no-build -c Release --logger "trx;LogFileName=results.trx" --results-directory TestResults' + } + post { + always { + junit testResults: 'TestResults/*.trx', allowEmptyResults: true + } + } + } + stage('Run Migrations') { steps { bat 'dotnet tool install --global dotnet-ef 2>nul || dotnet tool update --global dotnet-ef 2>nul' @@ -53,10 +64,37 @@ pipeline { bat 'az login --service-principal -u "%AZ_CLIENT_ID%" -p "%AZ_CLIENT_SECRET%" --tenant "%AZ_TENANT_ID%" --output none' bat 'az account set --subscription "%AZ_SUB_ID%"' bat 'az webapp deploy --resource-group rg-powdercoatinglogix-prod --name linuxpcl --src-path deploy.zip --type zip --async true' + bat 'az webapp restart --resource-group rg-powdercoatinglogix-prod --name linuxpcl' bat 'az logout' } } } + + stage('Health Check') { + steps { + powershell ''' + $url = "https://linuxpcl.azurewebsites.net/" + $timeout = 180 + $elapsed = 0 + Write-Host "Polling $url for up to $timeout seconds..." + do { + Start-Sleep -Seconds 10 + $elapsed += 10 + try { + $r = Invoke-WebRequest $url -UseBasicParsing -TimeoutSec 10 + if ($r.StatusCode -lt 400) { + Write-Host "App responded HTTP $($r.StatusCode) after ${elapsed}s" + exit 0 + } + } catch { + Write-Host "[${elapsed}s] Not yet responding: $_" + } + } while ($elapsed -lt $timeout) + Write-Error "App did not come healthy within $timeout seconds" + exit 1 + ''' + } + } } post {