Test CMake - BredaUniversityGames/JenkinsLib GitHub Wiki
Runs CTest and publishes JUnit results to Jenkins. Supports both preset-based testing (from CMakePresets.json) and manual CTest invocation using the build context.
With presets:
stages {
git.sync()
cmake.build()
cmake.test()
// ...
}Standalone (test preset configures and builds automatically if needed):
stages {
git.sync()
cmake.test()
// ...
}When CMakePresets.json contains testPresets:
| Parameter | Default | Description |
|---|---|---|
CMAKE_TEST_PRESET |
(first preset) | CTest preset (dropdown populated from CMakePresets.json) |
When no test presets are found, cmake.test() uses the build context from cmake.build(). No additional parameters are added.
Note: In manual mode,
cmake.test()requirescmake.build()to run first so it can read the build directory and configuration from context.
- Looks up the test preset's
configurePresetinCMakePresets.json - If the test preset's configure preset differs from the build preset's configure preset, automatically runs configure + build for the test configuration
- Runs
ctest --preset <preset> --output-on-failure --output-junit <results> - Publishes JUnit XML results to Jenkins
- Marks the build as
UNSTABLEif any tests fail
- Reads
ctx.cmakeBuildDirandctx.buildConfigfrom the build stage context - Runs
ctest -C <config> --output-on-failure --output-junit <results>in the build directory - Publishes JUnit XML results to Jenkins
- Marks the build as
UNSTABLEif any tests fail
When a test preset references a different configurePreset than what was used during cmake.build(), the test stage automatically runs its own configure + build step before testing. This allows test-specific configurations (e.g., with sanitizers or coverage flags) without affecting the main build.
| Issue | Solution |
|---|---|
| "requires cmake.build() or cmake.workflow() to run first" | In manual mode, add cmake.build() before cmake.test()
|
| No test preset dropdown | Ensure your CMakePresets.json contains non-hidden testPresets
|
| "has no configurePreset defined" | Add a configurePreset field to your test preset in CMakePresets.json
|
| Tests pass locally but fail in CI | Check that test fixtures and data files are available in the workspace |