ci: add Jenkins pipeline with JaCoCo coverage reports
This commit is contained in:
Vendored
+90
@@ -0,0 +1,90 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
GRADLE_USER_HOME = '/var/jenkins_home/.gradle'
|
||||
GRADLE_OPTS = '-Dorg.gradle.parallel=true -Dorg.gradle.caching=true'
|
||||
TESTS_STARTED = 'false'
|
||||
VERIFICATION_SUCCEEDED = 'false'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Clean') {
|
||||
steps {
|
||||
// A failed clean must not publish a previous build's reports.
|
||||
withGradle {
|
||||
sh './gradlew clean --no-daemon --console=plain'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Tests and coverage') {
|
||||
steps {
|
||||
script { env.TESTS_STARTED = 'true' }
|
||||
withChecks(name: 'Test', includeStage: true) {
|
||||
withGradle {
|
||||
// Continue independent verification while retaining a nonzero exit on failure.
|
||||
sh './gradlew test jacocoTestReport jenkinsPipelineTest --continue --parallel --max-workers=2 --build-cache --no-daemon --console=plain'
|
||||
}
|
||||
}
|
||||
script { env.VERIFICATION_SUCCEEDED = 'true' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
script {
|
||||
if (env.TESTS_STARTED == 'true') {
|
||||
// Attempt each publisher even if another publisher fails.
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
junit testResults: 'build/test-results/test/TEST-*.xml',
|
||||
checksName: 'Test / Tests and coverage',
|
||||
allowEmptyResults: env.VERIFICATION_SUCCEEDED != 'true'
|
||||
}
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
if (fileExists('build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml')) {
|
||||
withChecks(name: 'JaCoCo Coverage', includeStage: false) {
|
||||
recordCoverage(tools: [[parser: 'JACOCO', pattern: 'build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml']],
|
||||
id: 'jacoco',
|
||||
name: 'JaCoCo Coverage',
|
||||
checksName: 'JaCoCo Coverage',
|
||||
enabledForFailure: true,
|
||||
failOnError: true,
|
||||
sourceDirectories: [[path: 'src/main/java']],
|
||||
sourceCodeEncoding: 'UTF-8',
|
||||
sourceCodeRetention: 'EVERY_BUILD',
|
||||
qualityGates: [
|
||||
[threshold: 50.0, metric: 'CLASS', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 50.0, metric: 'METHOD', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 50.0, metric: 'LINE', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 50.0, metric: 'INSTRUCTION', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 40.0, metric: 'BRANCH', baseline: 'PROJECT', criticality: 'UNSTABLE']])
|
||||
}
|
||||
} else if (env.VERIFICATION_SUCCEEDED == 'true') {
|
||||
error 'Successful verification is missing the JaCoCo XML report.'
|
||||
} else {
|
||||
echo 'Verification failed before coverage was available; preserving available test reports.'
|
||||
}
|
||||
}
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
publishHTML(target: [
|
||||
allowMissing: env.VERIFICATION_SUCCEEDED != 'true',
|
||||
alwaysLinkToLastBuild: false,
|
||||
keepAll: true,
|
||||
reportDir: 'build/reports/jacoco/jacocoTestReport/html',
|
||||
reportFiles: 'index.html',
|
||||
reportName: 'Coverage Report'
|
||||
])
|
||||
}
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
archiveArtifacts artifacts: 'build/test-results/test/**, build/reports/tests/test/**, build/reports/jacoco/**, build/jacoco/*.exec',
|
||||
allowEmptyArchive: env.VERIFICATION_SUCCEEDED != 'true',
|
||||
onlyIfSuccessful: false
|
||||
}
|
||||
} else {
|
||||
echo 'Preparation did not complete; no current test run to publish. See the build console for diagnostics.'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
# Jenkins tests and JaCoCo coverage
|
||||
|
||||
Configure a Jenkins Pipeline from SCM using this repository and the Script Path
|
||||
`files/config/Jenkinsfile`. The pipeline follows the Prometeu Studio reference,
|
||||
adapted to AIE's single Gradle project and Java 25 target.
|
||||
|
||||
Use a Unix agent with Git, JDK 25 and dependency/cache access. No GraalVM compiler,
|
||||
native executable, sibling project, model CLI or model credentials are required.
|
||||
The checked-in Gradle Wrapper selects Gradle 9.3.1; no named Jenkins Gradle tool
|
||||
installation is needed. `GRADLE_USER_HOME` defaults to `/var/jenkins_home/.gradle`,
|
||||
matching Studio; adjust it if the chosen agent uses another writable cache path.
|
||||
The AIE CLI has no display requirement. Unlike Studio, this pipeline does not add
|
||||
global `JAVA_TOOL_OPTIONS`: the JVM prints that variable to stderr and would pollute
|
||||
the CLI output captured by the separate-process continuity tests.
|
||||
|
||||
The controller needs Declarative Pipeline, Gradle (`withGradle`), JUnit, Checks API
|
||||
(`withChecks`), Coverage (`recordCoverage`) and HTML Publisher plugins. An appropriate
|
||||
SCM checks provider is needed to publish commit checks. These are the same report
|
||||
steps used by Studio; this repository does not install or configure controller plugins.
|
||||
|
||||
## Commands and reports
|
||||
|
||||
```sh
|
||||
./gradlew clean --no-daemon --console=plain
|
||||
./gradlew test jacocoTestReport jenkinsPipelineTest --continue --parallel --max-workers=2 --build-cache --no-daemon --console=plain
|
||||
```
|
||||
|
||||
Clean runs separately so a preparation failure cannot publish stale reports as a
|
||||
new test run. `--continue` retains a failing exit code while allowing independent
|
||||
verification to finish. `test` finalizes with `jacocoTestReport`; invoking the report
|
||||
task directly consumes existing execution data. CI schedules both tasks explicitly;
|
||||
the report has an ordering constraint rather than a dependency on test success,
|
||||
so a failed test cannot suppress available coverage. JaCoCo 0.8.14 is pinned for Java 25 support.
|
||||
The report includes the main Java source set without coverage-driven exclusions.
|
||||
|
||||
| Output | Workspace-relative location |
|
||||
|---|---|
|
||||
| JUnit XML | `build/test-results/test/TEST-*.xml` |
|
||||
| Test HTML | `build/reports/tests/test/index.html` |
|
||||
| JaCoCo XML | `build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml` |
|
||||
| Coverage HTML | `build/reports/jacoco/jacocoTestReport/html/index.html` |
|
||||
| Raw JaCoCo data | `build/jacoco/test.exec` |
|
||||
|
||||
JUnit completes the check `Test / Tests and coverage`; the separate coverage check
|
||||
is `JaCoCo Coverage`. Configure required SCM check names to match these values.
|
||||
Coverage gates match Studio: CLASS, METHOD, LINE and INSTRUCTION at 50%, BRANCH at
|
||||
40%, baseline PROJECT, criticality UNSTABLE. A missed coverage gate makes the Jenkins
|
||||
build unstable; it does not convert a failed test run into a successful build.
|
||||
No extra local `jacocoTestCoverageVerification` threshold is imposed.
|
||||
|
||||
## Failure reporting
|
||||
|
||||
After verification starts, the unconditional post block attempts JUnit, Coverage,
|
||||
HTML and raw artifact publication independently. An exception in one publisher
|
||||
does not suppress the others. Coverage processing errors fail publication and
|
||||
coverage is enabled for failed builds. The archive retains test XML/binary output,
|
||||
test HTML, coverage XML/HTML and raw `.exec` data on failed and unstable builds too.
|
||||
Retention follows the Jenkins job's build/artifact policy.
|
||||
|
||||
Successful verification must produce nonempty JUnit results, coverage XML and HTML.
|
||||
Missing successful-build evidence fails publication. Compilation or setup failure
|
||||
may leave no reports; available diagnostics are retained and the original build
|
||||
failure remains authoritative. A failed clean attempts no publishers.
|
||||
|
||||
## Local validation and limits
|
||||
|
||||
```sh
|
||||
./gradlew jenkinsPipelineTest --console=plain
|
||||
```
|
||||
|
||||
This task executes the actual Jenkinsfile with controlled Pipeline steps, using
|
||||
Gradle's bundled Groovy without a new application/test dependency. Eleven cases
|
||||
exercise success, failed clean with stale paths, failed verification with partial
|
||||
reports, no reports, missing successful-build reports and isolated publisher errors.
|
||||
The task is also part of `check` and is invoked explicitly by this pipeline.
|
||||
|
||||
JUnit/JaCoCo reports come from the JVM `test` task. Separate CLI subprocesses and
|
||||
native smoke tests are not instrumented by the worker's JaCoCo agent; the report
|
||||
does not claim native or external-provider coverage. Tests use deterministic
|
||||
fixtures and require no real model calls.
|
||||
|
||||
The local Pipeline fixture is not a Jenkins controller or a plugin implementation.
|
||||
It cannot certify plugin compatibility, actual SCM checks or UI publication. A run
|
||||
of the configured Jenkins job is required to verify those integration details.
|
||||
Existing GitHub Actions native builds remain a separate workflow.
|
||||
|
||||
References: [Gradle JaCoCo plugin](https://docs.gradle.org/current/userguide/jacoco_plugin.html),
|
||||
[JaCoCo 0.8.14 / Java 25](https://github.com/jacoco/jacoco/releases/tag/v0.8.14),
|
||||
[JUnit](https://www.jenkins.io/doc/pipeline/steps/junit/),
|
||||
[Coverage](https://www.jenkins.io/doc/pipeline/steps/coverage/) and
|
||||
[HTML Publisher](https://www.jenkins.io/doc/pipeline/steps/htmlpublisher/).
|
||||
Reference in New Issue
Block a user