opticyclic
opticyclic

Reputation: 8116

How Do I Fail A Build In Jenkins If The Number Of Compiler Warnings Increases?

In TeamCity I can add a Build Failure condition that fails the build if the number of compiler/inspection warnings increases from the previousl successful build

https://confluence.jetbrains.com/display/TCD9/Build+Failure+Conditions#BuildFailureConditions-Failbuildonmetricchange

How do I do the same thing in Jenkins?

Upvotes: 7

Views: 3306

Answers (2)

CamM
CamM

Reputation: 818

The warnings plugin has been deprecated and replaced by the Warnings Next Generation Plugin. The equivalent feature is referred to as a Quality Gate.

Use a Quality Gate type of "NEW", with a threshold of 1, to fail the build if there are new issues since the last successful build.

If using pipelines, this stage will parse the results, and fail if there is a new lint failure present.

stage('lint') {
  steps {
    // ..generate eslint report, other types are supported by the plugin...
  }
  post {
    always {
      // record lint issues found, also, fail the build if there are ANY NEW issues found
      recordIssues enabledForFailure: true,
        blameDisabled: true,
        tools: [esLint(pattern: 'checkstyle-results.xml')],
        qualityGates: [[threshold: 1, type: 'NEW']]
    }
  }
}

Upvotes: 5

BitwiseMan
BitwiseMan

Reputation: 1937

The Warnings Plug-in should do exactly what you want. It will mark the build as unstable or failed based on the number of warnings, or optionally new warnings of specific priorities.

Fail build on any new compiler warnings

If you set "All priorities" to "0" as shown, it should do what you want. If that is not sufficient, the plugin also includes the options "Use delta for new warnings", "Use previous build as reference", and "Only use stable builds as reference" with detailed descriptions of how each of those options changes the behavior.

Upvotes: 5

Related Questions