Building CMake Project with Jenkins on Windows

Jenkins is an open-source continuous integration tool. I am new to Jenkins. To get familiar with it, I decided to start learning from a CMake project written with Dynamsoft Barcode Reader.

Prerequisites

Initializing Jenkins Environment

Stop and start Jenkins

After installing Jenkins by running setup wizard, you can visit localhost:8080 to initialize the Jenkins environment. To stop Jenkins, run cmd.exe as administrator and use the command ‘net stop jenkins’. To manually run Jenkins, use command ‘net start jenkins’ or ‘java -jar Jenkins.war’.

Admin password

Login Jenkins account with the initial password which is located at ‘Jenkins\secrets\initialAdminPassword’.

Customize plugins

On the plugin selection page, you can install plugins. I needed a clean environment, and therefore I closed the page without installing any plugin.

Jenkins cutomize

Manage users

Click ‘Jenkins > Manage Jenkins > Manage Users > Create User’ to add a new user.

 Jenkins user

Building CMake Project

So far, the Jenkins environment is ready. Click ‘New Item’ to create a new project.

Jenkins project

The Source Code Management is none. Don’t worry, because I didn’t install any SCM plugin. Save the configuration and jump to the project page.

Jenkins project

Click ‘Build Now’ to generate an empty project at Jenkins\workspace\dbr.

Jenkins first build

Get the source code https://github.com/dynamsoft-dbr/cmake.git. Copy source code to the folder. In addition, copy Barcode Reader 5.2\Components\C_C++\Lib\DBRx64.lib and Barcode Reader 5.2\Components\C_C++\Redist\DynamsoftBarcodeReaderx64.dll to platforms\win folder.

Jenkins source code

Click Workspace. You can see all files are listed.

Jenkins workspace

Windows batch command

Click Configure > Build to add ‘Execute Windows batch command’.

mkdir build
cd build
cmake -G"Visual Studio 14 2015 Win64" ..
cmake --build .

Jenkins build command

Save the commands and click ‘Build Now’.

I got following error message when building the project:

The system cannot find the file specified
ERROR: Cannot run program “cmake”

Jenkins error

No idea what happened. After re-installing Jenkins, the error was gone.

CMake plugin for Jenkins

Using CMake plugin is a better way to build CMake project.

Download CMake plugin.

Click Jenkins > Manage Jenkins > Manage Plugins > Advanced to add the plugin.

Jenkins cmake plugin

Switch back to the configuration page, and we can now see the CMake build options.

Jenkins cmake build

Fill out the build options as follows:

Jenkins cmake build option

Build the project to generate Jenkins\workspace\dbr\build\Release:

Jenkins build project

References