π Scenario 03: HTML Reports Chaos
Overview
This scenario teaches you how to generate, archive, and view beautiful HTML test reports in Jenkins, making your CI/CD results visually clear and enterprise-ready.
π Directory Structure
Jenkins/jenkins_scenarios/scenario_03_html_reports/
βββ Dockerfile
βββ Jenkinsfile
βββ README.md
βββ report_generator.py
βββ requirements.txt
βββ tests/
βββ test_config_validation_pass.py
βββ test_config_validation_fail.py
βββ test_api_health_pass.py
βββ test_api_health_fail.py
βββ test_postgres_pass.py
βββ test_postgres_fail.py
βββ test_redis_pass.py
βββ test_redis_fail.py
βββ test_secret_scan_pass.py
βββ test_secret_scan_fail.py
β How to Set Up the Pipeline in Jenkins UI
- Open Jenkins in your browser.
- Click "New Item".
- Enter a name (e.g.,
scenario_03_html_reports), select Pipeline, and click OK. - In the pipeline config:
- Under Pipeline script, select Pipeline script from SCM.
- Set SCM to Git and enter your repository URL.
- Set Script Path to
Jenkins/jenkins_scenarios/scenario_03_html_reports/Jenkinsfile. - Click Save.
β How to Run the Pipeline
- Click "Build with Parameters" (if parameters are defined).
- Click Build.
- Watch the console output for test execution and report generation.
- Download/view HTML reports from Jenkins artifacts after the build completes.
β What the Pipeline Does
- Builds a Docker image with all dependencies
- Runs a suite of Python tests (config validation, API health, DB, Redis, secrets)
- Generates HTML and JSON reports for each test
- Archives reports as Jenkins build artifacts
π§ͺ Chaos Testing Scenarios
β Scenario 1: Report Generation Failures
def test_report_generation_failure():
"""Simulate HTML report generation failures"""
try:
# Simulate disk space issues
if os.path.exists("/tmp/disk_full"):
raise OSError("No space left on device")
# Generate report
generate_html_report(test_results)
except Exception as e:
# Fallback to simple text report
generate_text_report(test_results)
assert "text" in str(e).lower() or "space" in str(e).lower()
β Scenario 2: Slow Report Generation
def test_slow_report_generation():
"""Test report generation under load"""
import time
start_time = time.time()
# Generate large report
large_dataset = [{"test": f"test_{i}", "result": "pass"} for i in range(10000)]
generate_html_report(large_dataset)
# Verify it completes within reasonable time
assert time.time() - start_time < 30.0
β Scenario 3: Corrupted Report Data
def test_corrupted_report_data():
"""Test handling of corrupted test data"""
corrupted_data = [
{"test": "valid_test", "result": "pass"},
{"test": "corrupted_test", "result": None}, # Corrupted
{"test": "another_test", "result": "fail"}
]
# Should handle corrupted data gracefully
report = generate_html_report(corrupted_data)
assert "corrupted_test" in report
assert "error" in report.lower()
β Troubleshooting
- Reports not found:
- Check the archive path in the Jenkinsfile matches the reports output directory.
- Ensure the tests generate reports in the expected location.
- Build fails:
- Check for missing dependencies in
requirements.txt. - Review the Docker build logs for errors.
- HTML not rendering:
- Download the HTML report and open it in your browser.
β Useful Commands
- See running containers:
bash docker ps - Check logs for a container:
bash docker logs <container_id> - Remove a container:
bash docker rm -f <container_id>
π Monitoring & Reporting
β Report Metrics
- Report generation time
- Report file size
- Number of tests reported
- Report accessibility score
β Chaos Metrics
- Report generation failure rate
- Recovery time from report failures
- Data corruption detection rate
Next: Scenario 01: Docker Build | Scenario 02: Testcontainers | Scenario 04: Manage Secrets | Scenario 05: Deploy to EKS
This scenario helps you master enterprise-grade reporting in Jenkins, making your CI/CD results clear and actionable! π₯