diff --git a/Jenkinsfile b/Jenkinsfile index 4fdba57..65bf144 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,6 +3,7 @@ pipeline { docker { image 'mcr.microsoft.com/dotnet/sdk:9.0' args '-u root:root' + label "${params.AGENT_LABEL?.trim() ?: 'docker'}" } } @@ -21,6 +22,7 @@ pipeline { string(name: 'SONAR_TOKEN_ID', defaultValue: '', description: 'Secret Text credential ID that stores the SonarQube token') string(name: 'SONAR_ORG', defaultValue: '', description: 'Optional SonarQube organization key') string(name: 'BUILD_CONFIGURATION', defaultValue: 'Release', description: 'dotnet build configuration') + string(name: 'AGENT_LABEL', defaultValue: 'docker', description: 'Agent label that has Docker CLI available') } environment { @@ -259,7 +261,13 @@ pipeline { post { always { echo '=== Post-build: archiving logs ===' - archiveArtifacts artifacts: 'Logs/**/*.log', allowEmptyArchive: true + script { + try { + archiveArtifacts artifacts: 'Logs/**/*.log', allowEmptyArchive: true + } catch (org.jenkinsci.plugins.workflow.steps.MissingContextVariableException ignore) { + echo 'Workspace unavailable when attempting to archive logs; skipping.' + } + } } success { echo 'Build finished successfully.' diff --git a/README.md b/README.md index 91baad6..e7c9f15 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ docker compose up --build ## Jenkins CI notes - The repo includes a declarative Jenkinsfile that builds on the `mcr.microsoft.com/dotnet/sdk:9.0` container image and expects Jenkins parameters for `GIT_REPO_URL`, `GIT_CREDENTIALS_ID`, `SONARQUBE_SERVER`, and `SONAR_TOKEN_ID`. Create the credentials in **Manage Jenkins › Credentials** before running the job. +- Set `AGENT_LABEL` (default `docker`) to a Jenkins agent that has the Docker CLI available so the pipeline can launch containers. - Update the Sonar project key or organization by editing `SONAR_PROJECT_KEY` / `SONAR_ORG` in the Jenkins parameter defaults or overriding them per-run; the pipeline passes these values to `dotnet-sonarscanner`. - The pipeline publishes unit-test results, OpenCover XML, and HTML coverage reports; open the “Code Coverage” HTML report in the Jenkins build sidebar or download the archived artifacts `artifacts/AS400API--/reports/coverage-html/index.html`. - SCA results (`security-reports/nuget-vulnerabilities.txt` and optional Dependency-Check HTML) and application logs from `Logs/` are archived automatically so you can review findings without re-running the build.