Integrating cppcheck Static Analysis into Jenkins with Git Polling
This guide explains how to set up Jenkins to automatically poll a Git repository, run cppcheck static analysis, process the XML results, and email the findings, including detailed configuration steps, command examples, and troubleshooting tips.
Step 1: Install Jenkins from the official site (http://jenkins-ci.org/).
Step 2: In Jenkins, go to System Management → Manage Plugins and install the cppcheck plugin.
Step 3: Install the Git plugin and Git client plugin.
Step 4: Install the cppcheck tool on the Jenkins server so it can be invoked from the command line.
Step 5: Create a new job (e.g., test ).
Step 6: In the job configuration, under Source Code Management , select Git and provide the repository URL and credentials (create an SSH credential with the Git username and private key; the key must belong to the jenkins user, not root).
Step 7: Add a Poll SCM trigger with the cron expression */1 * * * * to poll the repository every minute; if changes are detected, Jenkins updates the local branch and starts a build.
Step 8: Add an Execute shell build step with the cppcheck command:
cppcheck -j 4 --enable=all --inconclusive --xml --xml-version=2.2 > cppcheck.xmlThis runs cppcheck with four parallel jobs, enables all checks, treats inconclusive results as warnings, and writes the output in XML format to cppcheck.xml .
Step 9: Add another Execute shell step to analyse the XML result:
php analysis_xml.phpThis script parses cppcheck.xml and extracts key information.
Step 10: Configure email notifications in Jenkins to send the summary of cppcheck findings to the relevant stakeholders.
Common issues and tips:
Git authentication failures often occur because Jenkins runs as the jenkins user; ensure the SSH key is placed in the jenkins home directory with correct ownership.
Remote builds can be triggered by constructing a URL such as JENKINS_URL/job/projectname/build?token=TOKEN_NAME (or /buildWithParameters?token=TOKEN_NAME ) after creating a token in the user settings.
Periodic builds can also be scheduled via the “Build periodically” option.
The resulting cppcheck report is displayed in Jenkins as shown in the attached image.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.