Fix (again)
WinDiagnostics CI WinDiagnostics failed CI.
Beffroi/WinDiagnostics/pipeline/head There was a failure building this commit Details

This commit is contained in:
Dandaedre 2026-09-14 18:21:04 +02:00
parent 623a32165d
commit e82316c57b
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
1 changed files with 364 additions and 176 deletions

540
Jenkinsfile vendored
View File

@ -1,55 +1,26 @@
// Jenkins CI for WinDiagnostics
// Static validation only: the diagnostic script itself targets Windows.
//
// FreeBSD agent requirements: git and the shells/powershell package.
// Install once as root: pkg install git powershell
// Label the Jenkins node "freebsd". See README.md for setup details.
// PSScriptAnalyzer is saved into a workspace-local module directory.
// Add this webhook in Gitea:
// http://192.168.1.37:8080/gitea-webhook/post
pipeline {
agent {
label 'freebsd'
}
options {
timestamps()
disableConcurrentBuilds()
}
agent { label 'rust_no_docker' }
environment {
POWERSHELL_TELEMETRY_OPTOUT = '1'
// FreeBSD packages install executables under /usr/local/bin.
PATH = "/usr/local/bin:/usr/local/sbin:${env.PATH}"
PWSH = 'pwsh'
// Keep installed PowerShell modules inside the Jenkins workspace.
// Keep PowerShell modules inside the Jenkins workspace.
PS_MODULE_HOME = "${WORKSPACE}/.tools/psmodules"
}
stages {
stage('Check FreeBSD prerequisites') {
stage('Checkout') {
steps {
checkout scm
sh '''
set -eu
if [ "$(uname -s)" != "FreeBSD" ]; then
echo "This pipeline requires a FreeBSD agent labeled freebsd." >&2
exit 1
fi
if ! command -v git >/dev/null 2>&1 || ! command -v "$PWSH" >/dev/null 2>&1; then
echo "Missing git or pwsh. On the agent, install as root: pkg install git powershell" >&2
exit 1
fi
"$PWSH" -NoLogo -NoProfile -NonInteractive -Command '
$ErrorActionPreference = "Stop"
if ($PSVersionTable.PSVersion.Major -lt 7) {
throw "PowerShell 7 or later is required."
}
$PSVersionTable | Out-String | Write-Host
'
git submodule sync --recursive
git submodule update --init --recursive
'''
}
}
@ -59,15 +30,69 @@ pipeline {
sh '''
set -eu
echo "PowerShell:"
"$PWSH" --version
echo "Repository:"
git --version
git status --short
echo "System:"
uname -a
echo
echo "Architecture:"
uname -m
echo
echo "Git:"
git --version
echo
echo "Repository:"
git status --short
'''
}
}
stage('Setup PowerShell') {
steps {
sh '''
set -eu
# ---------------------------------------------------------
# PowerShell
# ---------------------------------------------------------
#
# WinDiagnostics itself targets Windows, but PowerShell
# Core is used here only for static parsing and linting.
#
# On this FreeBSD worker, pwsh should normally be provided
# by the existing worker environment.
# ---------------------------------------------------------
if command -v pwsh >/dev/null 2>&1; then
echo "PowerShell already installed."
else
echo "ERROR: pwsh was not found on this Jenkins worker." >&2
echo >&2
echo "Install PowerShell on the rust_no_docker worker:" >&2
echo " pkg install powershell" >&2
exit 1
fi
echo
echo "Using:"
pwsh --version
pwsh \
-NoLogo \
-NoProfile \
-NonInteractive \
-Command '
$ErrorActionPreference = "Stop"
if ($PSVersionTable.PSVersion.Major -lt 7) {
throw "PowerShell 7 or later is required."
}
$PSVersionTable |
Out-String |
Write-Host
'
'''
}
}
@ -77,55 +102,139 @@ pipeline {
sh '''
set -eu
"$PWSH" -NoLogo -NoProfile -NonInteractive -Command '
$ErrorActionPreference = "Stop"
echo "Checking PowerShell syntax..."
echo
# Limit validation to source files, excluding workspace caches.
$paths = @(git -c core.quotePath=false ls-files -- "*.ps1" "*.psm1" "*.psd1")
if ($LASTEXITCODE -ne 0) {
throw "Unable to list tracked PowerShell files."
}
$files = @($paths | ForEach-Object { Get-Item -LiteralPath $_ })
pwsh \
-NoLogo \
-NoProfile \
-NonInteractive \
-Command '
$ErrorActionPreference = "Stop"
if ($files.Count -eq 0) {
throw "No PowerShell files found."
}
$failed = $false
foreach ($file in $files) {
Write-Host "Parsing $($file.FullName)"
$tokens = $null
$errors = $null
[void][System.Management.Automation.Language.Parser]::ParseFile(
$file.FullName,
[ref]$tokens,
[ref]$errors
$paths = @(
git -c core.quotePath=false ls-files -- \
"*.ps1" \
"*.psm1" \
"*.psd1"
)
if ($errors.Count -gt 0) {
$failed = $true
if ($LASTEXITCODE -ne 0) {
throw "Unable to list tracked PowerShell files."
}
foreach ($parseError in $errors) {
Write-Host (
"{0}:{1}:{2}: {3}" -f
$file.FullName,
$parseError.Extent.StartLineNumber,
$parseError.Extent.StartColumnNumber,
$parseError.Message
)
$files = @(
$paths |
ForEach-Object {
Get-Item -LiteralPath $_
}
)
if ($files.Count -eq 0) {
throw "No PowerShell files found."
}
$failed = $false
foreach ($file in $files) {
Write-Host "Parsing $($file.FullName)"
$tokens = $null
$errors = $null
[void][
System.Management.Automation.Language.Parser
]::ParseFile(
$file.FullName,
[ref]$tokens,
[ref]$errors
)
if ($errors.Count -gt 0) {
$failed = $true
foreach ($parseError in $errors) {
Write-Host (
"{0}:{1}:{2}: {3}" -f
$file.FullName,
$parseError.Extent.StartLineNumber,
$parseError.Extent.StartColumnNumber,
$parseError.Message
)
}
}
}
}
if ($failed) {
throw "PowerShell parser validation failed."
}
if ($failed) {
throw "PowerShell parser validation failed."
}
Write-Host "All PowerShell files parsed successfully."
'
Write-Host ""
Write-Host "All PowerShell files parsed successfully."
'
'''
}
}
stage('Setup PSScriptAnalyzer') {
steps {
sh '''
set -eu
mkdir -p "${PS_MODULE_HOME}"
pwsh \
-NoLogo \
-NoProfile \
-NonInteractive \
-Command '
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
$moduleHome = $env:PS_MODULE_HOME
$separator = [IO.Path]::PathSeparator
$env:PSModulePath =
$moduleHome +
$separator +
$env:PSModulePath
if (
-not (
Get-Module \
-ListAvailable \
-Name PSScriptAnalyzer
)
) {
Write-Host (
"Installing PSScriptAnalyzer into " +
"$moduleHome..."
)
Save-Module \
PSScriptAnalyzer \
-Path $moduleHome \
-Repository PSGallery \
-Force \
-ErrorAction Stop
}
else {
Write-Host (
"PSScriptAnalyzer already installed."
)
}
Import-Module \
PSScriptAnalyzer \
-ErrorAction Stop
$module = Get-Module PSScriptAnalyzer
Write-Host (
"PSScriptAnalyzer version: " +
"$($module.Version)"
)
'
'''
}
}
@ -134,122 +243,169 @@ pipeline {
steps {
sh '''
set -eu
mkdir -p "$PS_MODULE_HOME"
"$PWSH" -NoLogo -NoProfile -NonInteractive -Command '
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
echo "Running PSScriptAnalyzer..."
echo
$moduleHome = $env:PS_MODULE_HOME
$separator = [IO.Path]::PathSeparator
$env:PSModulePath = $moduleHome + $separator + $env:PSModulePath
pwsh \
-NoLogo \
-NoProfile \
-NonInteractive \
-Command '
$ErrorActionPreference = "Stop"
if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
Write-Host "Installing PSScriptAnalyzer into $moduleHome..."
$separator = [IO.Path]::PathSeparator
Save-Module PSScriptAnalyzer `
-Path $moduleHome `
-Repository PSGallery `
-Force `
$env:PSModulePath =
$env:PS_MODULE_HOME +
$separator +
$env:PSModulePath
Import-Module \
PSScriptAnalyzer \
-ErrorAction Stop
}
Import-Module PSScriptAnalyzer -ErrorAction Stop
$paths = @(
git -c core.quotePath=false ls-files -- \
"*.ps1" \
"*.psm1" \
"*.psd1"
)
$module = Get-Module PSScriptAnalyzer
Write-Host "PSScriptAnalyzer version: $($module.Version)"
# Limit validation to source files, excluding workspace caches.
$paths = @(git -c core.quotePath=false ls-files -- "*.ps1" "*.psm1" "*.psd1")
if ($LASTEXITCODE -ne 0) {
throw "Unable to list tracked PowerShell files."
}
$files = @($paths | ForEach-Object { Get-Item -LiteralPath $_ })
if ($files.Count -eq 0) {
throw "No PowerShell files found."
}
$issues = @(
foreach ($file in $files) {
Invoke-ScriptAnalyzer `
-Path $file.FullName `
-Severity Error,Warning `
-ErrorAction Stop
if ($LASTEXITCODE -ne 0) {
throw "Unable to list tracked PowerShell files."
}
)
if ($issues.Count -gt 0) {
$issues |
Sort-Object ScriptName, Line, Column |
Format-Table `
Severity,
ScriptName,
Line,
Column,
RuleName,
Message `
-AutoSize |
Out-String |
Write-Host
}
$files = @(
$paths |
ForEach-Object {
Get-Item -LiteralPath $_
}
)
$errors = @(
$issues | Where-Object Severity -eq "Error"
)
if ($files.Count -eq 0) {
throw "No PowerShell files found."
}
$warnings = @(
$issues | Where-Object Severity -eq "Warning"
)
$issues = @(
foreach ($file in $files) {
Invoke-ScriptAnalyzer \
-Path $file.FullName \
-Severity Error,Warning \
-ErrorAction Stop
}
)
Write-Host (
"PSScriptAnalyzer: {0} error(s), {1} warning(s)." -f
$errors.Count,
$warnings.Count
)
if ($issues.Count -gt 0) {
$issues |
Sort-Object \
ScriptName,
Line,
Column |
Format-Table \
Severity,
ScriptName,
Line,
Column,
RuleName,
Message \
-AutoSize |
Out-String |
Write-Host
}
# Warnings are reported but do not fail CI.
# Static analyzer errors do fail the build.
if ($errors.Count -gt 0) {
throw "PSScriptAnalyzer reported errors."
}
'
$errors = @(
$issues |
Where-Object Severity -eq "Error"
)
$warnings = @(
$issues |
Where-Object Severity -eq "Warning"
)
Write-Host (
"PSScriptAnalyzer: {0} error(s), " +
"{1} warning(s)." -f
$errors.Count,
$warnings.Count
)
# Warnings are informative.
# Analyzer errors fail CI.
if ($errors.Count -gt 0) {
throw (
"PSScriptAnalyzer reported errors."
)
}
'
'''
}
}
stage('JSON Contract Sanity') {
stage('Validate JSON Contract') {
steps {
sh '''
set -eu
"$PWSH" -NoLogo -NoProfile -NonInteractive -Command '
$ErrorActionPreference = "Stop"
echo "Checking WinDiagnostics JSON report contract..."
echo
$script = Get-Content `
-LiteralPath "./WindowsMaintenanceReport.ps1" `
-Raw
if [ ! -f WindowsMaintenanceReport.ps1 ]; then
echo "ERROR: WindowsMaintenanceReport.ps1 is missing." >&2
exit 1
fi
$requiredMarkers = @(
"ConvertTo-Json",
"schema_version",
"report_type",
"generated_at",
"completed_at",
"sections"
)
pwsh \
-NoLogo \
-NoProfile \
-NonInteractive \
-Command '
$ErrorActionPreference = "Stop"
foreach ($marker in $requiredMarkers) {
if (-not $script.Contains($marker)) {
throw (
"Expected structured-report marker missing: " +
$marker
)
$script = Get-Content \
-LiteralPath "./WindowsMaintenanceReport.ps1" \
-Raw
$requiredMarkers = @(
"ConvertTo-Json",
"schema_version",
"report_type",
"generated_at",
"completed_at",
"sections"
)
foreach ($marker in $requiredMarkers) {
if (-not $script.Contains($marker)) {
throw (
"Expected structured-report marker " +
"missing: $marker"
)
}
Write-Host "Found: $marker"
}
}
Write-Host "Structured JSON report contract markers found."
'
Write-Host ""
Write-Host (
"Structured JSON report contract looks valid."
)
'
'''
}
}
stage('Repository Sanity') {
steps {
sh '''
set -eu
echo "Tracked PowerShell files:"
git ls-files -- '*.ps1' '*.psm1' '*.psd1'
echo
echo "CI validation complete."
'''
}
}
@ -257,11 +413,43 @@ pipeline {
post {
success {
echo 'PowerShell syntax and static analysis passed.'
publishChecks(
conclusion: 'SUCCESS',
name: 'WinDiagnostics CI',
summary: 'WinDiagnostics passed all CI integrity checks.',
text: 'PowerShell parsing, PSScriptAnalyzer, and JSON report contract validation completed successfully.',
title: 'WinDiagnostics validation successful'
)
echo '✅ WinDiagnostics integrity checks passed.'
}
failure {
echo 'WinDiagnostics integrity checks failed.'
publishChecks(
conclusion: 'FAILURE',
name: 'WinDiagnostics CI',
summary: 'WinDiagnostics failed CI.',
text: 'A checkout, PowerShell parsing, static analysis, or JSON contract validation step failed. Check the Jenkins log.',
title: 'WinDiagnostics CI failed'
)
echo '❌ WinDiagnostics integrity checks failed.'
}
unstable {
publishChecks(
conclusion: 'ACTION_REQUIRED',
name: 'WinDiagnostics CI',
summary: 'WinDiagnostics CI is unstable.',
text: 'The Jenkins build completed with an unstable status.',
title: 'WinDiagnostics CI unstable'
)
echo '⚠️ WinDiagnostics CI is unstable.'
}
always {
echo 'CI finished.'
}
}
}