Quarantine Tests in Jenkins, Keep the History, Agents Too
The fastest way to silence a flapping test in Jenkins is a hard skip. The build goes green, and a few months later nobody remembers why the test is disabled or whether it ever passed reliably. The history is gone, and so is the signal that would have told you whether the instability was growing or shrinking.
Quarantine is the right instinct, done properly: the test keeps running and keeps producing results, but its outcome no longer blocks the build. That matters more in agentic quality engineering. Coding agents edit tests and pipeline files in pull requests, and adding a skip or a quarantine marker is an easy way for an agent to turn a red check green. If quarantine is a separate, recorded state with its own history, those changes stay visible and reviewable instead of quietly shrinking the suite.
This article gives a Declarative Pipeline pattern that runs quarantined tests in their own stage, preserves their JUnit XML in a queryable store, finds re-admission candidates with SQL, and enforces limits so the quarantine list does not become a graveyard.
Learn Node.js, Cucumber, GitHub Copilot, APIs, CI/CD, and modern automation by building a complete framework.
What Quarantine Actually Means in a Jenkins Context
Quarantine is not the same as skip. A skipped test produces no result — it vanishes from your pass/fail denominator and silently inflates your pass rate, a distortion that corrupts every rate you report. A quarantined test still runs, still emits a JUnit XML result, but its outcome is decoupled from the build's success gate. The distinction matters enormously for trend data.
In Jenkins terms, this means running quarantined tests in a dedicated stage with catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE'), publishing their XML to a separate report path, and archiving that path as an artifact on every build. The main pipeline gate never sees the flaky result; the history store always does. That separation is what lets you answer "has this test been failing more or less over the last 30 builds?" — which is the only question worth asking before you decide to fix or delete it.
Building the Quarantine Stage: Pipeline, XML Tagging, and Trend Queries
Start with a Pytest marker. Tag every quarantined test with @pytest.mark.quarantine and keep the list in a flat file (quarantine.txt) committed to the repo. Your CI reads the file; your engineers own the list. No magic, no external service required at this stage.
# Jenkinsfile (Declarative)
pipeline {
agent any
stages {
stage('Test: Main Suite') {
steps {
sh 'pytest tests/ -m "not quarantine" --junitxml=results/main.xml'
}
post {
always { junit 'results/main.xml' }
}
}
stage('Test: Quarantine Suite') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
sh 'pytest tests/ -m quarantine --junitxml=results/quarantine.xml'
}
}
post {
always {
junit testResults: 'results/quarantine.xml',
allowEmptyResults: true,
skipMarkingBuildUnstable: true
archiveArtifacts artifacts: 'results/quarantine.xml',
allowEmptyArchive: true
}
}
}
}
}
The catchError wrapper is the key: failures in the quarantine stage mark the stage UNSTABLE but leave currentBuild.result as SUCCESS. By default the junit step marks the whole build UNSTABLE when it records test failures, so the quarantine stage sets skipMarkingBuildUnstable: true. Jenkins still publishes the JUnit XML, so the trend graph and any downstream aggregation pipeline see every result. For richer Jenkins test reporting, point the JUnit plugin at both XML paths and use the "Health Report Amplification Factor" to weight the quarantine results at zero for badge purposes — they're visible in the trend but not counted against the build health score.
To make trend data queryable beyond the builds Jenkins retains, ship the XML to a time-series store on every build. A small Python post-processor parses the JUnit output and writes rows to PostgreSQL (or ClickHouse if you're at scale):
import xml.etree.ElementTree as ET, psycopg2, os
from datetime import datetime, timezone
def ingest(xml_path, suite_tag, build_id):
tree = ET.parse(xml_path)
rows = []
for tc in tree.iter('testcase'):
status = 'pass'
if tc.find('failure') is not None or tc.find('error') is not None: status = 'fail'
if tc.find('skipped') is not None: status = 'skip'
rows.append((
build_id, suite_tag, tc.get('classname'),
tc.get('name'), float(tc.get('time', 0)),
status, datetime.now(timezone.utc)
))
conn = psycopg2.connect(os.environ['PG_DSN'])
cur = conn.cursor()
cur.executemany(
"""INSERT INTO test_runs
(build_id, suite, classname, test_name, duration_s, status, ts)
VALUES (%s,%s,%s,%s,%s,%s,%s)""", rows)
conn.commit()
ingest('results/quarantine.xml', 'quarantine', os.environ['BUILD_NUMBER'])
With history in PostgreSQL, a single query surfaces re-admission candidates — tests that have passed consistently for the last N builds:
SELECT test_name,
COUNT(*) FILTER (WHERE status = 'pass') AS passes,
COUNT(*) FILTER (WHERE status = 'fail') AS fails,
ROUND(100.0 * COUNT(*) FILTER (WHERE status = 'pass') / COUNT(*), 1) AS pass_pct
FROM test_runs
WHERE suite = 'quarantine'
AND ts > NOW() - INTERVAL '30 days'
GROUP BY test_name
HAVING COUNT(*) >= 20
ORDER BY pass_pct DESC;
Any test above 95% pass rate over 20+ runs is a re-admission candidate; anything below 40% after 30 days is a deletion candidate. Run weekly and posted to a Slack channel, this query replaces manual digging through build pages with a short review of a ranked list. Pair this with an SLO-style threshold — if quarantine list size exceeds 5% of total test count, open an automatic Jira ticket — to prevent the list from becoming a graveyard. That kind of SLO-driven approach to test reliability keeps the quality gate honest.
Where Quarantine Pipelines Break Down in Practice
The quarantine list becomes a write-only store. Engineers add tests when they're flapping but there's no process to remove them. After six months the list has 80 entries, nobody owns them, and the quarantine stage takes longer than the main suite. The fix is a mandatory TTL: every entry in quarantine.txt gets a date comment, and a pre-merge check rejects entries older than 60 days that haven't been triaged. Automation enforces what process won't.
History is only kept in Jenkins' local build store. Jenkins' JUnit trend only covers the builds you retain, and it disappears when old builds are discarded or the controller is rebuilt. Teams discover this after a migration when all historical context is gone. Shipping XML to an external store (PostgreSQL, ClickHouse, BigQuery) on every build is not optional if you want to do any meaningful quality tracking over time. The ingestion script above is a small post-build step, and its data survives any Jenkins infrastructure change.
Quarantine rules for agent-authored changes
Treat the quarantine list as a controlled file, because it is the cheapest lever anyone (person or agent) has for changing what the build gate sees. Three rules keep it honest when coding agents open pull requests:
- Quarantine changes need a person. Put
quarantine.txtand the pytest marker registration under a CODEOWNERS entry, so adding or removing a test from quarantine always gets a human approval. - Every entry carries evidence. The pull request that quarantines a test links to builds where it both passed and failed on the same commit. "It failed once on my branch" is a regression report, not a flake.
- Re-admission needs the trend, not one green run. An agent that "fixes" a quarantined test should cite the re-admission query above, or attach repeated runs on one commit, before the marker is removed.
Record the author type on each ingested row as well. If the build has a commit author or bot account, store it next to suite so you can report how many quarantined tests were introduced or last changed by an agent, and how many agent-proposed fixes were later re-quarantined. That second number is the one that tells you whether the review gate works.
Finally, keep tests that call a model out of the quarantine stage entirely. Their results vary by design, so a quarantine pass rate for them means nothing. Run them in their own non-blocking evaluation stage and report a pass rate over N runs against a threshold. The quarantine versus fix guide covers when quarantine is the right call at all.
Myths That Keep Flaky Tests in Limbo
"Quarantine is a temporary fix, so it doesn't need process." In practice, "temporary" in CI means permanent unless you build the eviction mechanism before you need it. The same applies to the belief that a green build means the suite is healthy — a quarantine list hiding 30 failing tests produces a green build that is meaningfully less reliable than the badge suggests. Pass rate on the main suite is not a proxy for suite health when a material fraction of tests are excluded from the gate.
"Flakiness is a test problem, not a system problem." Much persistent flakiness in Python test suites traces to shared state, timing dependencies, or environment variance — none of which are fixed by re-running the test. Tools like pytest-flakefinder and pytest-randomly help surface ordering dependencies, but the root cause is almost always in the application or the test infrastructure. Quarantine buys time to investigate; it doesn't substitute for investigation. Treating quarantine as resolution is how suites accumulate technical debt that never shows up in any dashboard.
Quarantine done right is a holding pattern with a defined exit: either the test gets fixed and re-admitted, or it gets deleted with a record of why. The pipeline pattern above — separate stage, preserved XML, external history store, weekly SQL triage query — gives you that exit. If you're evaluating whether Jenkins' native reporting is enough to support this workflow long-term, the comparison in CircleCI Insights vs Jenkins test reporting is worth reading before you commit to a tooling investment.
Note: This article is for informational purposes only and is not a substitute for professional advice. If you need guidance on specific situations described in this article, consider consulting a qualified professional.