just ram

stuff I should remember

Code analysis

This post is part of a series:

  1. Jenkins.NET
  2. Jenkins.NET Plugins
  3. Setup Jenkins.NET
  4. Setting up your first job
  5. Your first build
  6. Breaking the build
  7. Diagnosing and fixing a broken build
  8. Monitoring your build
  9. Running your tests
  10. Code Analysis
  11. Security
  12. Active Directory Security

Jenkins can run a series of code analysis tools after each build, this will help you monitor the health of your solution.

Compiler Warnings

Ideally your solution will have no compiler warnings and you can have your solution fail to build if the any warnings appear. I know in the real world this isn’t always possible, so we can utilize Jenkins to make sure the number of warnings do not get out of hand.

This is accessed via the Jobs configuration page, for our Demo job we click Jenkins » Demo » Configure. You’ll find the “Scan for compiler warnings” at the bottom of this page under the “Post-Build Actions” section.

Configure

code 1

  • Tick the “Scan for compiler warnings”
  • Click the “Add” button under the “Scan console log” area
  • Select MSBuild from the Parser drop down list
  • Click the “Save” button

Now when you carry out a build, you’ll get a compiler warnings section as part of your build report.

Warnings report

code 2

Here we have no compiler warnings so I’ll commit a warning to show the information Jenkins tracks.

code 3

We now have 2 compiler warnings and we can drill down for more details by clicking the 2 warnings link.

code 4

We can continue drilling and find the actual source file and line number causing the warning.

code 5

As well as the low level details Jenkins also gives us a Compiler Warnings Trend graph.

code 6

Your mission is to reverse this trend and keep your compiler warnings low or preferably non-existent.

Tasks and To-dos

Another sign of Technical Debt is lots of To-dos, hack, and fix-me comments in your code. Lets use Jenkins to monitor these type of comments. For our Demo job we click Jenkins » Demo » Configure. You’ll find the “Scan workspace for open tasks” at the bottom of this page under the “Post-Build Actions” section.

Configure

code 7

  • Tick the “Scan workspace for open tasks” check box
  • In the “Files to scan” textbox enter: */.cs which scans all C Sharp files for these comments.
  • In the “Tasks tags” High priority textbox enter: HACK, FIXME
  • In the “Tasks tags” Normal priority textbox enter: TODO, TO-DO
  • Tick the “Ignore case” check box
  • Click the “Save” button

These task tags can be anything you or your team use to indicate work that needs to be carried out in your source. When we carry out a build, we’ll get a compiler warnings section as part of our build report.

Task Scanner Report

code 8

Here we have no tasks, I’ll commit a few To-dos and Hack comments to show the information Jenkins tracks.

code 9

We now have 3 open tasks and we can drill down for more details by clicking the 3 open tasks link.

code 10

As you can see depending on the priority of the open task we get different color bars to indicate they severity.

We can continue drilling and find the actual source file and line number of the tasks.

code 11

As well as the low level details Jenkins also gives us an Open Tasks Trend graph.

code 12

Comments