DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Jenkins in the Age of Kubernetes: Strengths, Weaknesses, and Its Future in CI/CD
  • Instant Integrations With API and Logic Automation
  • Microservices Testing: Key Strategies and Tools
  • Deploy an Application for Azure Container Registry

Trending

  • Enforcing Architecture With ArchUnit in Java
  • Chat With Your Knowledge Base: A Hands-On Java and LangChain4j Guide
  • GitHub Copilot's New AI Coding Agent Saves Developers Time – And Requires Their Oversight
  • The Future of Java and AI: Coding in 2025
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Integration of C-STAT Code Analysis with Automated Jenkins CI Build

Integration of C-STAT Code Analysis with Automated Jenkins CI Build

Take a look at how you can futher you static code analysis by integrating with Jenkins.

By 
Sankara M user avatar
Sankara M
·
Apr. 02, 19 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
11.8K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

Most of us are aware there is always a limitation or challenge in setting up CI/CD for embedded software, and we have also seen in some cases there are still no alternate options available, which leads to manual effort and misses in code quality.

In this article, we are going to see one such embedded development tool (IAR Embedded workbench) and how we can integrate C-STAT static code analysis with a continuous integration build (Jenkins), as well as how to set some quality gates with an automated build.

Prerequisites:

a. IAR Embedded Workbench (IDE)

b. C-STAT license

c. Jenkins Setup

IAR Embedded workbench tool provides us the command line execution options to achieve the static code analysis of the IAR project. Now we will see how it works.

IAR Command Line Utility

The IAR system provides us a utility called IarBuild.exe, which is used to perform the analysis in the command line. You can find the IarBuild.exe utility in the installation path as shown below.

C:\Program Files (x86) \IAR Systems\Embedded Workbench 8.1\common\bin\

Run Code Analysis:

First navigate to the above path in the command path and execute the below command to analyse the complete project.

IarBuild.exe D:\sample\project\setup\sample.ewp -cstat_analyze Debug


Where,

  • D:\sample\project\setup\sample.ewp is the path of your IAR project file

  •  -cstat_analyze  is the command to analyze

  •  Debug is the configuration mode of the project

By executing the above command, it will perform the static code analysis for your complete project and the results will be stored in a cstat.db file under the path ...project\setup\Debug\Obj\.

Note The next time you run the code analysis, if you have made any changes to your source code files since the previous analysis, then you must first clear the database to avoid issues due to mixing of old and new data in the database file.

Clear Analysis Results

To clear the database file using the command line, execute the below command,

IarBuild.exe D:\sample\project\setup\sample.ewp -cstat_clean Debug


Generate Report

To generate a report, we can use the IREPORT tool provided by IAR which you can find in the same installation directory. The IREPORT tool is used to produce the HTML report of previous code analyses performed by the C-STAT.

The report represents statistical data both in numbers and as tables. Two different types of reports can be generated:

● An outline that features info regarding, for example, project-wide enabled checks, the total amount of messages, suppressed checks (if any), messages for each check, etc.

● A full report that contains the constant info such as the outline, and additional info regarding all suppressed and non-suppressed messages at the conclusion of the report. The tables can be collapsed and expanded, and the columns can be sorted

To generate the full HTML report, we can execute the below command,

ireport.exe --db D:\sample\project\setup\Debug\Obj\cstat.db --project D:\sample\project \setup\sample.ewp --full --output D:\sample\result.html


The above command contains four parameters:

 --db specifies the path of the database file the report is based on

 --project specifies the project file

 --full generates full report containing information about suppressed and non-suppressed checks.

 --output specifies the name of the output result file.

Integrating the C-STAT With Jenkins CI build:

There is no direct plugin or method available to integrate this CSTAT to any CI tools. But we can achieve the custom integration in the below method,

So now we know the commands for analyzing, cleaning and generatingthe report file. Using these command, we can easily write a batch script file (.bat) file and then call this batch file in Jenkins as a pre-build command execution step.

Set Threshold Gateway

We will come across the scenario where we need to define the gateway in the CI build by setting the threshold value for Low, Medium and High issues. If the value is greater then set value, then we can make the build as a failure.

By default, C-STAT doesn’t provide us the option to set this value. But we can achieve this using custom scripting as below.

So we can get the HTML report containing the analysis result of Low, medium and high issue count. These values are captured inside the HTML result file in the format data: [0-9, 0-9 ,0-9].

Please refer to the below screen shot of batch scripting to understand how I get these values in a variable and then validate it with sea t threshold value.

Image title

Jenkins Build Result

Given below the build log from Jenkins CI build for your reference. You can see the build is failed due to 19 issues identified as Medium priority.

Image title

Conclusion

Here, we have seen how to automate the C-STAT analysis with the Jenkins CI build and how to set the threshold gateway to determine the build status. I hope this blog will be helpful for those who are working with IAR embedded workbench and would like to automate the C-STAT with your CI build system.

Continuous Integration/Deployment Jenkins (software) Integration Database Command (computing)

Opinions expressed by DZone contributors are their own.

Related

  • Jenkins in the Age of Kubernetes: Strengths, Weaknesses, and Its Future in CI/CD
  • Instant Integrations With API and Logic Automation
  • Microservices Testing: Key Strategies and Tools
  • Deploy an Application for Azure Container Registry

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!