Interview Prep/Jenkins/Pipeline design & Jenkinsfile decisions

You need the build to be UNSTABLE when coverage drops below 80% but still produce an artifact. How?

BeginnerScenarioPipeline design & Jenkinsfile decisions
Answer

Situation read → A soft gate: visible signal, no blocked delivery for this branch.

What I'd do →

  1. Parse coverage in a step and call unstable:
    script {
      def pct = sh(script: "jq '.total.lines.pct' coverage/coverage-summary.json", returnStdout: true).trim() as Double
      if (pct < 80) { unstable("Line coverage ${pct}% is below 80%") }
    }
    
  2. Or use the Coverage plugin's recordCoverage with quality gates set to unstable.
  3. Make main deploy stages require currentBuild.currentResult == 'SUCCESS' if unstable builds must not ship.

Why → UNSTABLE is Jenkins' built-in "passed with warnings" state.

Interview tip → Explain the difference between result and currentResult.

All Jenkins questions Roadmap: Jenkins

More on Pipeline design & Jenkinsfile decisions