Skip to content

πŸ“Š 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

  1. Open Jenkins in your browser.
  2. Click "New Item".
  3. Enter a name (e.g., scenario_03_html_reports), select Pipeline, and click OK.
  4. In the pipeline config:
  5. Under Pipeline script, select Pipeline script from SCM.
  6. Set SCM to Git and enter your repository URL.
  7. Set Script Path to Jenkins/jenkins_scenarios/scenario_03_html_reports/Jenkinsfile.
  8. Click Save.

βœ… How to Run the Pipeline

  1. Click "Build with Parameters" (if parameters are defined).
  2. Click Build.
  3. Watch the console output for test execution and report generation.
  4. 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! πŸ”₯