jenkins the definitive guide

(Jeff_L) #1

weather icon is normally related to the number of failing builds in the previous five builds, but Jenkins
can also take into account other factors, such as code quality results. Displaying a cloudy or stormy icon
for a project on the dashboard is a much better way of raising awareness about code quality issues that
simply relying on graphs and reports on the build job page.


To set this up, you need to go back to the Report Violations section in the Post-build Actions. The first
three columns in Figure 9.4, “Configuring the violations plugin for a Freestyle project” show a sunny
icon, a stormy icon, and a yellow ball. The one with the sunny icon is the maximum number of violations
tolerated in order to keep the sunny weather icon on the dashboard page. The second column, with the
stormy weather icon, is the number of violations that will cause a stormy icon to appear on the dashboard.
If you have a number of violations between these two extremes, you will get one of the cloudy icons.


You can set different values for different tools. The exact thresholds will vary between teams and
between projects, and also between tools. For example, Checkstyle will typically raise a lot more issues
than FindBugs or CPD, with PMD being somewhere in between. You need to adjust the values you use
to reflect how these tools work on your code base, and your expectations.


You can take this even further with the third column (the one with the yellow ball). This column lets you
set a number of violations that will cause the build to be declared unstable. Remember, when a build
becomes unstable Jenkins will send out notification messages, so this is an even more proactive strategy.


For example, in Figure 9.4, “Configuring the violations plugin for a Freestyle project”, we have
configured the minimum number of Checkstyle violations to 10, which means that the sunny weather
icon will only appear if there are 10 or fewer Checkstyle violations. If there are more than 10, the weather
will degrade progressively, until at the 200 violations mark, it will become stormy. And if there are 500
or more Checkstyle violations, the project will be flagged as unstable.


Now look at the configuration for CPD, the duplicated code detector that comes with PMD. In this
project, we have adopted a zero-tolerance policy for duplicated code, so the sunny icon value is set to
zero. The stormy icon is set to 10, so if there are 10 or more copy-paste violations, the project weather
indicator will appear as stormy. And if the project has 15 or more copy-paste violations, it will be
declared unstable.


Now, on the Dashboard page, this project will appear both with a stormy weather icon and as unstable,
even though there are no test failures (see Figure 9.7, “Configuring the violations plugin for a Freestyle
project”). This particular build is unstable because there are 16 CPD violations. In addition, if you place
your mouse over the weather icon, Jenkins will display some more details about how it calculated this
particular status.

Free download pdf