If you would like to mark a build as failed based on the findings in the review, you can define custom failure conditions in your configuration file.
We use a simple DSL for defining failure conditions, let's take a look at a few examples:
build_failure_conditions: - 'elements.rating(<= D).exists' # No classes/methods with a rating of D or worse - 'elements.rating(<= D).new.exists' # No new classes/methods with a rating of D or worse # allowed (useful for legacy code) - 'patches.label("Doc Comments").exists' # No doc comments patches allowed - 'patches.label("Spacing").new.count > 1' # More than 1 new spacing patch - 'issues.label("coding-style").exists' # No coding style issues allowed - 'issues.label("coding-style").new.exists' # No new coding style issues allowed - 'issues.label("coding-style").new.count > 5' # More than 5 new coding style issues. - 'issues.severity(>= MAJOR).new.exists' # New issues of major or higher severity - 'project.metric("scrutinizer.quality", < 6)' # Code Quality Rating drops below 6 - 'project.metric("scrutinizer.test_coverage", < 0.60)' # Code Coverage drops below 60% # Code Coverage decreased from previous inspection - 'project.metric_change("scrutinizer.test_coverage", < 0)' # Code Coverage decreased from previous inspection by more than 10% - 'project.metric_change("scrutinizer.test_coverage", < -0.10)'
If one of your failure conditions is satisfied, Scrutinizer will set the build status to failed.
The condition scope is the first part of each condition. In the above examples, we saw the scopes
issues; here is a full reference of all available scopes:
|elements:||All code elements including f.e. classes, functions, methods, etc.|
|operations:||All functions and methods.|
Filters are used to narrow down the initial scope further. In the example above, we already introduced some filters
new. Some filters like
rating are not available for all scopes; for example, this
filter does not make sense on the
Filters for issues¶
These filters can only applied when using the
|new:||Only new issues.|
Filters for other scopes¶
These filters can be applied when using all scopes except
|new:||Only new elements.|
The last part of the condition is an assertion. Typically you want to use
exists here to check whether one
item matches the filters which you have set-up.
The other use-case is to use
count and compare it against a fixed number, e.g.
issues.count > 5 (more than 5