Build CMake - BredaUniversityGames/JenkinsLib GitHub Wiki
Configures and builds a CMake project. Supports both CMakePresets.json preset-based builds and manual generator/config/platform builds.
stages {
git.sync()
cmake.build()
// ...
}With overrides:
stages {
git.sync()
cmake.build(
CMAKE_BUILD_PRESETS: ['debug-build', 'release-build']
)
// ...
}Manual mode (no presets):
stages {
git.sync()
cmake.build(
CMAKE_SOURCE_DIR: 'engine',
CMAKE_GENERATOR_CHOICES: ['Ninja', 'Visual Studio 17 2022']
)
// ...
}- CMake installed and on
PATHon the build agent - Visual Studio installed (located automatically via
vswhere.exe) - A
CMakePresets.jsonin the project root (for preset-based builds)
When CMakePresets.json is detected, the pipeline shows preset-based parameters:
| Parameter | Default | Description |
|---|---|---|
CMAKE_SOURCE_DIR |
. |
Path to the directory containing CMakeLists.txt
|
CMAKE_BUILD_PRESET |
(first preset) | Build preset (dropdown populated from CMakePresets.json) |
CMAKE_ARGS |
(empty) | Additional CMake configure arguments |
CMAKE_BUILD_ARGS |
(empty) | Additional CMake build arguments |
When no presets are found, the pipeline falls back to manual parameters:
| Parameter | Default | Description |
|---|---|---|
CMAKE_SOURCE_DIR |
. |
Path to the directory containing CMakeLists.txt
|
CMAKE_BUILD_DIR |
build |
Build output directory |
CMAKE_GENERATOR |
Visual Studio 18 2026 |
CMake generator (Ninja, Visual Studio 18 2026, Visual Studio 17 2022, Visual Studio 16 2019, Unix Makefiles) |
CMAKE_CONFIG |
Debug |
Build configuration (Debug, Release, RelWithDebInfo, MinSizeRel) |
CMAKE_PLATFORM |
x64 |
Target platform (x64, Win32, ARM64) |
CMAKE_ARGS |
(empty) | Additional CMake configure arguments |
CMAKE_BUILD_ARGS |
(empty) | Additional CMake build arguments |
The module discovers presets in order:
-
Override lists — Presets passed directly in the Jenkinsfile (e.g.,
CMAKE_BUILD_PRESETS: [...]) -
Workspace file — Reads
CMakePresets.jsonfrom the workspace (fast path, works when the workspace persists between builds) -
VCS remote — Fetches
CMakePresets.jsonfrom the Git or Perforce remote (auto-detected from pipeline parameters)
Note: On the very first run, presets may not be available yet. Run the job once so the library can discover your presets, then subsequent runs will show preset dropdowns.
Preset mode:
- Derives the configure preset from the selected build preset
- Runs
cmake --preset <configure-preset>(with any extraCMAKE_ARGS) - Runs
cmake --build --preset <build-preset>(with any extraCMAKE_BUILD_ARGS)
Manual mode:
- Runs
cmake -S <source> -B <build> -G <generator> -DCMAKE_BUILD_TYPE=<config>(adds-A <platform>for Visual Studio generators) - Runs
cmake --build <build> --config <config>
Before running any CMake command, the module automatically:
- Locates the latest Visual Studio installation using
vswhere.exe - Runs
vcvarsall.batwith the correct architecture (x64,x86, oramd64_arm64)
This ensures compilers and build tools are available without manual setup.
After execution, cmake.build() sets the following on the pipeline context:
| Key | Preset Mode | Manual Mode |
|---|---|---|
ctx.buildEngine |
'CMake' |
'CMake' |
ctx.cmakeBuildPreset |
Selected preset name | (not set) |
ctx.buildConfig |
(not set) | Selected configuration |
ctx.buildPlatform |
(not set) | Selected platform |
ctx.cmakeBuildDir |
(not set) | Build directory path |
Override default choices by passing maps to cmake.build():
| Override Key | Description |
|---|---|
CMAKE_BUILD_PRESETS |
List of build preset names to show in the dropdown |
CMAKE_SOURCE_DIR |
Default source directory |
CMAKE_BUILD_DIR |
Default build directory (manual mode) |
CMAKE_GENERATOR_CHOICES |
List of generators for the dropdown |
CMAKE_CONFIG_CHOICES |
List of configurations for the dropdown |
CMAKE_PLATFORM_CHOICES |
List of platforms for the dropdown |
CMAKE_ARGS |
Default configure arguments |
CMAKE_BUILD_ARGS |
Default build arguments |
- cmake.test() — Run CTest with preset or manual configuration
- cmake.pack() — Package build output with CPack
- cmake.workflow() — Run a full CMake workflow preset
These methods are available on the cmake object for advanced or custom pipelines:
| Method | Description |
|---|---|
cmake.configure(config) |
Manual configure (sourceDir, buildDir, generator, config, platform, args) |
cmake.configureWithPreset(config) |
Configure with a preset (preset, args) |
cmake.buildProject(config) |
Manual build (buildDir, config, platform, buildArgs) |
cmake.buildWithPreset(config) |
Build with a preset (preset, buildArgs) |
cmake.install(config) |
Install (buildDir, config, prefix) |
cmake.testWithPreset(config) |
Run CTest with a preset (preset, resultsFile) |
cmake.packageProject(config) |
Manual CPack (buildDir, config, generator, args) |
cmake.packageWithPreset(config) |
Run CPack with a preset (preset) |
cmake.workflowWithPreset(config) |
Run a workflow preset (preset) |
| Issue | Solution |
|---|---|
| No preset dropdowns on first run | Run the job once so the library discovers your CMakePresets.json, then re-run |
| "Could not discover presets" | Ensure CMakePresets.json exists in CMAKE_SOURCE_DIR and VCS credentials are configured |
| CMake or compiler not found | Ensure CMake is on PATH and Visual Studio is installed on the build agent |
| Wrong Visual Studio version | The module uses vswhere -latest; install the desired VS version or set a specific generator |
| Manual parameters shown instead of presets | Ensure your CMakePresets.json contains non-hidden buildPresets
|