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 {