Coderrect and Jenkins Integration (Using freestyle project)
This tutorial shows how to integrate Coderrect with Jenkins, the most popular CI/CD platform.
Coderrect is a static analysis tool for C/C++ code. Unlike popular tools such as Cppcheck and Clang static analyzer, one of the powerful features of Coderrect is the detection of concurrency races caused by code using explicit multi-thread APIs (e.g. PThread, std::thread) or implicit parallel APIs (e.g. OpenMP).
Besides running Coderrect to scan the local source code via the command line, you can easily integrate it with Jenkins to include it in your CI/CD pipeline so that Coderrect can be triggered automatically by a pull request, a code check-in, or a scheduled nightly build.
The diagram below illustrates the interaction among components in Coderrect-Jenkins integration.
When a build is scheduled Jenkins master asks Jenkins agents to prepare the source code (usually pull the latest code from a source control system), build the project, test and analysis the program.
Upon receiving the request from Jenkins Master, the Jenkins agent runs Coderrect installed locally to analyze the code and report discoveries back to the master.
The first step is to install the Coderrect package to the Jenkins agent machine. Note that Coderrect just supports Linux for now.
Install Coderrect Jenkins Plugin
You can download Coderrect Jenkins plugin file here. Then go to the “Advanced” tab of “Manage Plugins” page.
For “Upload Plugin”, click “Choose File” to select the downloaded coderrect.hpi.
Create a Freestyle project
Now we can create a freestyle project in Jenkins.
Go to Jenkins portal and click “New Item“.
Enter the project name (TDEngine here) and select “Freestyle project”
Set up the source control and build information. For the build stage, I create the following script commands
The last step “coderrect -e taosd -t make” tells coderrect to
- Execute “make” to build binaries
- Analyze an executable called “taosd” to detect races
- Generate a terminal-based race report besides the default HTML-based report
Set up the post-build stage by choosing “Publish the race report to Jenkins”
Since we run “coderrect” under the project_root/build, we specify a relative path “build” so that coderrect knows where to find the race report.
You are ready to go ffter you click “Save”!
Trigger a Build
Coderrect adds a section into the build summary page. The section shows the number of races in different categories for this build and the previous build. For example, the demo project above has 13 data races.
You can click the “Coderrect” item in the navigation bar to see detail report.
The detail report has three views – full, new and solved. The “full” view shows all races found from the current build. The “new” view shows just races introduced by the new committed code since previous build. The “solved” view shows races fixed by the new code.
I hope you enjoy this post. Please send to firstname.lastname@example.org if you have any feedback.