// Moved from docs/05-operations/jenkins-pipeline-guide.adoc to docs/working/archive/operations/jenkins-pipeline-guide.adoc on 2026-06-16 (docs reorg Phase 2) = StarForth Jenkins Pipeline Guide :toc: left :toclevels: 2 :sectnums: :source-highlighter: groovy :icons: font == Overview This document describes the StarForth Jenkins pipeline architecture and how to use it across different environments (Developer, Test, QA, Production). **Current Status:** Developer Pipeline (baseline) is complete **Next Steps:** Test/QA/Production pipelines derived from this baseline --- == Pipeline Architecture ### Current: Developer Pipeline (Jenkinsfile) A comprehensive torture test and verification pipeline for continuous integration during development. **Duration:** ~2 hours **Scope:** Full system validation + formal verification + packaging **Pipeline Flow:** ``` 1. 🧹 Cleanup & Preparation ↓ 2. πŸ”¨ Build Gauntlet (4 configurations) β”œβ”€ DEBUG β”œβ”€ STANDARD β”œβ”€ FASTEST └─ FAST ↓ 3. πŸ§ͺ Smoke Test ↓ 4. βœ… Comprehensive Test Suite (936 tests) ↓ 5. πŸ‡ Benchmark Gauntlet β”œβ”€ Quick benchmark (1M iterations) β”œβ”€ Full benchmark suite β”œβ”€ Stack operations stress (10M) β”œβ”€ Arithmetic operations stress (10M) └─ Logic operations stress (10M) ↓ 6. πŸ’€ Extreme Stress Tests β”œβ”€ Deep recursion limits β”œβ”€ Maximum stack depth β”œβ”€ Memory allocation patterns β”œβ”€ Long-running stability └─ Nested loops ↓ 7. πŸ”₯ Thermal & Performance Monitoring ↓ 8. 🧠 Memory Leak Detection (Valgrind) ↓ 9. ⚑ Profile-Guided Optimization Build ↓ 10. πŸ“Š PGO Performance Comparison ↓ 11. 🎯 Edge Case Testing β”œβ”€ Division by zero β”œβ”€ Stack underflow β”œβ”€ Stack overflow └─ Invalid memory access ↓ 12. πŸ“ˆ Performance Regression Check ↓ 13. πŸ” Code Quality Checks β”œβ”€ Compiler warnings └─ Lines of code analysis ↓ 14. πŸ”¬ Formal Verification & Isabelle Theories β”œβ”€ Build Isabelle theories (audit mode) β”œβ”€ Refinement status check β”œβ”€ Code annotation validation β”œβ”€ Refinement report generation └─ Archive formal verification artifacts ↓ 15. πŸ“š Documentation Build β”œβ”€ API documentation (Doxygen) β”œβ”€ LaTeX conversion └─ Archive documentation ↓ 16. πŸ“¦ Package Build (DEB & RPM) β”œβ”€ Debian package (if fpm available) └─ RPM package (if fpm available) ↓ 17. πŸ“‹ Generate Test Report ↓ βœ… SUCCESS or ❌ FAILURE ``` --- ## Stage Details ### Stages 1-13: Existing Testing & Analysis See Jenkinsfile comments for details. These validate: - βœ… Code compilation (4 configurations) - βœ… Functional correctness (936 tests) - βœ… Performance (benchmarks & regression) - βœ… Stability (stress tests, thermal monitoring) - βœ… Memory safety (leak detection) - βœ… Resilience (edge cases, error handling) - βœ… Code quality (warnings, metrics) ### Stage 14: πŸ”¬ Formal Verification & Isabelle Theories (NEW) **Purpose:** Verify C implementation against formal spec **Steps:** 1. Check Isabelle availability 2. Build Isabelle theories (audit mode - never fails even with incomplete proofs) 3. Check refinement status (CAPA tracking) 4. Validate code annotations against theory 5. Generate refinement report 6. Archive all formal verification artifacts **Artifacts Produced:** - `isabelle-docs/` - Theory documentation (AsciiDoc + build logs) - `REFINEMENT_CAPA.adoc` - Defect tracking log - `refinement-status.md` - Status report - `REFINEMENT_ANNOTATIONS.adoc` - Code annotation guide - `REFINEMENT_ROADMAP.adoc` - Implementation roadmap - Logs: `isabelle-build.log`, `refinement-status.log`, `annotation-check.log` **Logs:** - `isabelle-build.log` - Theory verification output (most critical) - `refinement-status.log` - Refinement defect counts - `annotation-check.log` - Code annotation coverage **Success Criteria:** - Stage always succeeds (graceful handling if Isabelle not installed) - All artifacts archived for auditor review ### Stage 15: πŸ“š Documentation Build (NEW) **Purpose:** Generate complete documentation suite **Generates:** - API documentation from Doxygen (XML β†’ AsciiDoc) - LaTeX versions for formal reports - All documentation properly archived **Artifacts:** - `api-docs/` - API reference documentation - `latex-docs/` - LaTeX sources for formal documents ### Stage 16: πŸ“¦ Package Build (DEB & RPM) (NEW) **Purpose:** Build distribution packages **Requirements:** - `fpm` (Effing Package Manager) for packaging ```bash sudo apt-get install ruby-dev gem install fpm ``` **Produces:** - `starforth_*.deb` - Debian package - `starforth-*.rpm` - Red Hat package **Graceful Degradation:** - Skips if `fpm` not installed - Shows helpful installation message --- ## Artifacts & Logs All artifacts and logs are archived in Jenkins and available for download. ### Artifacts Directory (`artifacts/`) ``` artifacts/ β”œβ”€β”€ starforth-debug # Debug build (O0, symbols) β”œβ”€β”€ starforth-standard # Standard optimized build β”œβ”€β”€ starforth-fastest # Maximum optimization build β”œβ”€β”€ starforth-fast # Fast build (no LTO) β”œβ”€β”€ starforth-pgo # PGO optimized build β”œβ”€β”€ starforth_*.deb # Debian package β”œβ”€β”€ starforth-*.rpm # Red Hat package β”‚ β”œβ”€β”€ isabelle-docs/ # Isabelle theory documentation β”œβ”€β”€ REFINEMENT_CAPA.adoc # Formal verification defect log β”œβ”€β”€ refinement-status.md # Refinement status report β”œβ”€β”€ REFINEMENT_ANNOTATIONS.adoc # Code annotation guide β”œβ”€β”€ REFINEMENT_ROADMAP.adoc # Implementation roadmap β”‚ β”œβ”€β”€ api-docs/ # API documentation β”œβ”€β”€ latex-docs/ # LaTeX documentation β”‚ └── test-report.md # Comprehensive test report ``` ### Logs Directory (`logs/`) ``` logs/ β”œβ”€β”€ system-info.log # Build machine info β”‚ β”œβ”€β”€ build-debug.log # DEBUG build output β”œβ”€β”€ build-standard.log # STANDARD build output β”œβ”€β”€ build-fastest.log # FASTEST build output β”œβ”€β”€ build-fast.log # FAST build output β”œβ”€β”€ build-pgo.log # PGO build output β”œβ”€β”€ compiler-warnings.log # Compiler warnings β”œβ”€β”€ loc-analysis.txt # Lines of code analysis β”‚ β”œβ”€β”€ smoke-test.log # Smoke test output β”œβ”€β”€ full-test-suite.log # Complete test suite (936 tests) β”œβ”€β”€ test-summary.txt # Test results summary β”‚ β”œβ”€β”€ bench-quick.log # Quick benchmark (1M iterations) β”œβ”€β”€ bench-full.log # Full benchmark suite β”œβ”€β”€ bench-stack-torture.log # Stack operations (10M) β”œβ”€β”€ bench-math-torture.log # Arithmetic operations (10M) β”œβ”€β”€ bench-logic-torture.log # Logic operations (10M) β”œβ”€β”€ pgo-comparison.log # PGO vs regular performance β”œβ”€β”€ performance-baseline.csv # Performance metrics β”‚ β”œβ”€β”€ stress-recursion.log # Recursion limit test β”œβ”€β”€ stress-stack-depth.log # Stack depth test β”œβ”€β”€ stress-memory.log # Memory allocation test β”œβ”€β”€ stress-long-run.log # Long-running stability β”œβ”€β”€ stress-nested-loops.log # Nested loops test β”‚ β”œβ”€β”€ edge-div-zero.log # Division by zero handling β”œβ”€β”€ edge-stack-underflow.log # Stack underflow handling β”œβ”€β”€ edge-stack-overflow.log # Stack overflow handling β”œβ”€β”€ edge-invalid-memory.log # Invalid memory access β”‚ β”œβ”€β”€ thermal-test.log # Sustained load test β”œβ”€β”€ system-metrics.csv # System load during test β”‚ β”œβ”€β”€ valgrind-leak-check.log # Memory leak detection β”‚ β”œβ”€β”€ isabelle-build.log # Isabelle theory build (CRITICAL) β”œβ”€β”€ refinement-status.log # Refinement status β”œβ”€β”€ annotation-check.log # Code annotation validation β”œβ”€β”€ refinement-report.log # Refinement report generation β”‚ β”œβ”€β”€ api-docs-build.log # API documentation build β”œβ”€β”€ docs-latex-build.log # LaTeX conversion β”‚ β”œβ”€β”€ package-build.log # Package build configuration β”œβ”€β”€ deb-build.log # Debian package build └── rpm-build.log # RPM package build ``` --- ## Pipeline Variants (Future) The current Developer Pipeline is the baseline. Future variants: ### Test Pipeline (Jenkinsfile.test) - Reduced scope: Stages 1-8, 13-17 - Skip: Stages 9-12 (PGO, performance comparison, regression) - Focus: Correctness + formal verification + packaging - Duration: ~1 hour - Use: Integration testing, per-commit validation ### QA Pipeline (Jenkinsfile.qa) - Focus on validation: Stages 1-7, 13-17 - Include: Edge case testing, code quality - Skip: Long-running stress tests, PGO builds - Add: Artifact signing, release notes generation - Duration: ~45 minutes - Use: Release candidates, manual QA gates ### Production Pipeline (Jenkinsfile.prod) - Minimal scope: Stages 1-4, 13-17 - Add: Security scanning, package signing, upload to repositories - Focus: Fast feedback, artifact publication - Skip: Benchmarks, stress tests, memory leak detection - Duration: ~15 minutes - Use: Final release builds, automatic repository upload **Derivation Pattern:** ``` Developer Pipeline (baseline - all stages) ↓ β”œβ”€β†’ Test Pipeline (stages: 1-8, 13-17) β”œβ”€β†’ QA Pipeline (stages: 1-7, 13-17) └─→ Production Pipeline (stages: 1-4, 13-17) ``` --- ## Using the Pipeline ### Local Development Run equivalent stages locally: ```bash # Single stage testing make smoke # Stage 3 make test # Stage 4 make bench # Stage 5 make docs-isabelle # Stage 14 (partial) make refinement-status # Stage 14 (partial) # Full pipeline equivalent make clean && make fastest # Stages 1-2 make test # Stage 4 make docs-isabelle # Stage 14 make deb # Stage 16 ``` ### Jenkins Integration **To use this pipeline:** 1. **Create a Jenkins job with this Jenkinsfile** ``` Job Name: StarForth-Develop Pipeline Script from SCM Repository: https://github.com/rajames440/StarForth.git Branch: master Script Path: Jenkinsfile ``` 2. **Install required tools on build agent:** ```bash # Isabelle (optional but recommended) wget https://isabelle.in.tum.de/dist/Isabelle2025_linux.tar.gz tar -xzf Isabelle2025_linux.tar.gz # Add to PATH # FPM (for packaging) sudo apt-get install ruby-dev sudo gem install fpm # Valgrind (for memory testing) sudo apt-get install valgrind # Doxygen (for API docs) sudo apt-get install doxygen ``` 3. **Configure Jenkins agent:** ``` Node: any (or specific builder) Timeout: 2 hours Workspace cleanup: enable (optional) Build retention: 10 builds ``` 4. **Run the pipeline:** ``` Trigger: Push to master (or manual) Monitor: Jenkins UI β†’ StarForth-Develop β†’ Build logs Artifacts: Jenkins UI β†’ Build artifacts ``` ### Reading the Pipeline Output **Key metrics to watch:** 1. **Build Stage** - Should complete in < 2 minutes per configuration 2. **Test Stage** - Should pass 936/936 tests 3. **Benchmark Stage** - Baseline for performance regression checks 4. **Stress Tests** - Verify stability under extreme load 5. **Memory Leak Detection** - Should show "No leaks" in summary 6. **Formal Verification** - Check `isabelle-build.log` for theory errors 7. **Refinement Status** - Monitor OPEN defects in REFINEMENT_CAPA.adoc 8. **Package Build** - Verify .deb and .rpm created successfully --- ## Customization ### Adding New Stages To add a new stage (e.g., performance regression): ```groovy stage('πŸ“Š New Analysis') { steps { echo "Running new analysis..." sh 'make new-target 2>&1 | tee ${LOG_DIR}/new-analysis.log' // Archive results sh 'cp results.json ${ARTIFACT_DIR}/ || true' } } ``` ### Conditional Execution Skip stages based on conditions: ```groovy stage('Name') { when { expression { currentBuild.result == null || currentBuild.result == 'SUCCESS' } } steps { // Only run if previous stages passed } } ``` ### Parallel Execution Run independent tests in parallel: ```groovy stage('Parallel Tests') { parallel { stage('Benchmark') { steps { sh 'make bench' } } stage('Memory Check') { steps { sh 'valgrind ./build/starforth' } } } } ``` --- ## Troubleshooting ### "Isabelle not found" **Solution:** ```bash # Install Isabelle wget https://isabelle.in.tum.de/dist/Isabelle2025_linux.tar.gz tar -xzf Isabelle2025_linux.tar.gz # Add to PATH: export PATH=$PATH:/path/to/Isabelle2025/bin ``` ### "fpm not found" (packaging skipped) **Solution:** ```bash sudo apt-get install ruby-dev sudo gem install fpm ``` ### "Valgrind: command not found" **Solution:** ```bash sudo apt-get install valgrind ``` ### Build timeout (2 hours exceeded) **Solution:** 1. Skip PGO build (Stages 9-10) 2. Skip thermal monitoring (Stage 7) 3. Reduce stress test iterations 4. Use faster hardware ### Pipeline fails at formal verification **Cause:** Isabelle theories have errors **Action:** 1. Review `logs/isabelle-build.log` 2. Check `REFINEMENT_CAPA.adoc` for tracked issues 3. Run `make refinement-status` locally 4. See REFINEMENT_ROADMAP.adoc for resolution steps --- ## Metrics & Reporting ### Performance Baseline Captured in `performance-baseline.csv`: ```csv timestamp,operation,iterations,duration_seconds 1635696000,stack_ops,1000000,1.234 1635696010,arithmetic,1000000,2.567 ``` **Use:** Track performance regressions across builds ### Test Coverage From test suite logs: - Total tests: 936 - Passing: (tracked by test runner) - Failing: (indicates bugs or regressions) ### Memory Profile From valgrind logs: ``` LEAK SUMMARY: definitely lost: 0 bytes indirectly lost: 0 bytes possibly lost: 0 bytes ``` **Success Criteria:** Zero leaks reported ### Formal Verification Metrics From refinement status: - Total defects: (count in REFINEMENT_CAPA.adoc) - OPEN: (active issues) - IN-PROGRESS: (being worked on) - CLOSED: (resolved) **Success Criteria:** OPEN β†’ 0 as phases complete --- ## Best Practices ### For Developers 1. **Check pipeline logs before pushing** - Run locally first 2. **Monitor formal verification** - Review REFINEMENT_CAPA.adoc regularly 3. **Keep stress tests passing** - Don't regress stability 4. **Follow annotation guide** - Add REFINEMENT headers to new code ### For DevOps 1. **Archive all artifacts** - Keep 10+ builds for analysis 2. **Monitor disk space** - Logs and artifacts accumulate 3. **Set alerts on failure** - Email or Slack notifications 4. **Rotate logs** - Keep for audit trail (90+ days) ### For Auditors 1. **Review formal verification section** - Core correctness evidence 2. **Check REFINEMENT_CAPA.adoc** - Tracking of all discrepancies 3. **Inspect code annotations** - Theory↔code correspondence 4. **Validate test coverage** - 936 tests + edge cases 5. **Check memory safety** - Valgrind reports --- ## Support & Questions **Q: How do I run the developer pipeline locally?** A: Use `make` targets directly: ```bash make smoke # Quick validation make test # Full test suite make docs-isabelle # Formal verification make deb rpm # Packaging ``` **Q: Can I run stages in parallel?** A: Some can (benchmarks, memory check). See "Parallel Execution" section. **Q: How do I skip certain stages?** A: Modify the Jenkinsfile to remove unwanted stages. Or create a new pipeline (test/qa). **Q: Where are the artifacts?** A: Jenkins β†’ Build β†’ Artifacts tab, or `artifacts/` directory in workspace. **Q: How do I integrate formal verification into my CI?** A: The pipeline already does! See Stage 14. --- ## Version Control This pipeline is maintained in: - **File:** `Jenkinsfile` (developer baseline) - **Future:** `Jenkinsfile.test`, `Jenkinsfile.qa`, `Jenkinsfile.prod` **Status:** ACTIVE **Last Updated:** 2025-10-30 **Next Review:** After first production deployment --- Generated: {docdate}