UNPKG

@cloudkinetix/bmad-enhanced

Version:

Cloud-Kinetix enhanced fork of BMAD-METHOD - Breakthrough Method of Agile AI-driven Development with robust versioning and unified validation.

544 lines (428 loc) โ€ข 17.8 kB
# analyze-pipeline-failures ## Task: Intelligent GitLab Pipeline Failure Analysis **Purpose**: Comprehensive analysis of pipeline failures with root cause identification, pattern detection, and actionable remediation strategies. **When to Use**: - After pipeline failures to identify root causes - Recurring failure pattern analysis - Pre-merge failure risk assessment - DevOps process improvement initiatives --- ## Task Configuration ### Input Parameters - `branch` (optional): Target branch to analyze (default: current branch) - `analysis_depth` (optional): shallow, standard, deep (default: standard) - `historical_analysis` (optional): Include pattern analysis across recent pipelines (default: true) - `generate_report` (optional): Generate detailed failure report (default: true) - `integration_alerts` (optional): Send failure alerts to integrated systems (default: true) ### Expected Outputs - Detailed failure analysis with root cause identification - Pattern detection across failed jobs - Actionable remediation recommendations - Integration alerts (JIRA bug reports, team notifications) - Historical failure trend analysis --- ## Task Execution ### Phase 1: Failure Discovery and Context Gathering ```bash # Verify authentication and branch context echo "๐Ÿ” Starting Pipeline Failure Analysis..." echo "=======================================" glab auth status || { echo "โŒ GitLab CLI not authenticated" exit 1 } ANALYSIS_BRANCH=${branch:-$(git branch --show-current)} echo "๐Ÿ“ Analyzing branch: $ANALYSIS_BRANCH" # Get current pipeline data PIPELINE_DATA=$(glab ci get --output json --branch "$ANALYSIS_BRANCH" 2>/dev/null) if [ $? -ne 0 ] || [ "$PIPELINE_DATA" = "" ]; then echo "โŒ No pipeline data available for analysis" echo " Branch: $ANALYSIS_BRANCH" exit 1 fi # Check if pipeline actually failed PIPELINE_STATUS=$(echo "$PIPELINE_DATA" | jq -r '.status') if [ "$PIPELINE_STATUS" != "failed" ]; then echo "โ„น๏ธ Pipeline status: $PIPELINE_STATUS" echo " This analysis is optimized for failed pipelines" echo " Continuing with general analysis..." fi echo "๐ŸŽฏ Pipeline ID: $(echo "$PIPELINE_DATA" | jq -r '.id')" echo "๐Ÿ“… Created: $(echo "$PIPELINE_DATA" | jq -r '.created_at')" echo "โฑ๏ธ Duration: $(echo "$PIPELINE_DATA" | jq -r '.duration // 0')s" ``` ### Phase 2: Failed Job Identification and Categorization ```bash echo "" echo "๐Ÿšจ Failed Job Analysis:" echo "======================" # Extract failed jobs FAILED_JOBS=$(echo "$PIPELINE_DATA" | jq -r '.jobs[] | select(.status == "failed") | .name') if [ -z "$FAILED_JOBS" ]; then echo "โœ… No failed jobs detected in current pipeline" # Check for other concerning statuses CONCERNING_JOBS=$(echo "$PIPELINE_DATA" | jq -r '.jobs[] | select(.status == "canceled" or .status == "skipped") | "\(.name): \(.status)"') if [ -n "$CONCERNING_JOBS" ]; then echo "" echo "โš ๏ธ Jobs with concerning statuses:" echo "$CONCERNING_JOBS" fi else echo "โŒ Failed jobs detected: $(echo "$FAILED_JOBS" | wc -l)" echo "" # Categorize failed jobs by stage and type echo "๐Ÿ“Š Failure Categorization:" echo "--------------------------" echo "$FAILED_JOBS" | while read job_name; do if [ -n "$job_name" ]; then # Get job details JOB_DATA=$(echo "$PIPELINE_DATA" | jq -r ".jobs[] | select(.name == \"$job_name\")") JOB_STAGE=$(echo "$JOB_DATA" | jq -r '.stage // "unknown"') JOB_ID=$(echo "$JOB_DATA" | jq -r '.id') JOB_DURATION=$(echo "$JOB_DATA" | jq -r '.duration // 0') echo "" echo "๐Ÿ”ด Job: $job_name" echo " Stage: $JOB_STAGE" echo " Duration: ${JOB_DURATION}s" echo " Job ID: $JOB_ID" # Categorize failure type based on job name patterns case "$job_name" in *test*|*spec*|*check*) echo " Category: ๐Ÿงช Test Failure" ;; *build*|*compile*) echo " Category: ๐Ÿ”จ Build Failure" ;; *deploy*|*release*) echo " Category: ๐Ÿš€ Deployment Failure" ;; *lint*|*format*|*style*) echo " Category: ๐Ÿ“ Code Quality Failure" ;; *security*|*scan*) echo " Category: ๐Ÿ”’ Security Scan Failure" ;; *) echo " Category: โ“ General Failure" ;; esac fi done fi ``` ### Phase 3: Root Cause Analysis Through Log Analysis ```bash echo "" echo "๐Ÿ”ฌ Root Cause Analysis:" echo "======================" if [ -n "$FAILED_JOBS" ]; then echo "$FAILED_JOBS" | while read job_name; do if [ -n "$job_name" ]; then echo "" echo "--- Analyzing: $job_name ---" # Get job ID for log retrieval JOB_ID=$(echo "$PIPELINE_DATA" | jq -r ".jobs[] | select(.name == \"$job_name\") | .id") if [ "$JOB_ID" != "null" ]; then # Retrieve and analyze logs echo "๐Ÿ“ Retrieving job logs..." JOB_LOGS=$(glab ci trace "$JOB_ID" 2>/dev/null) if [ -n "$JOB_LOGS" ]; then # Pattern-based failure analysis echo "๐Ÿ” Pattern Analysis:" # Check for common failure patterns if echo "$JOB_LOGS" | grep -qi "permission denied\|access denied"; then echo " ๐Ÿ”’ ROOT CAUSE: Permission/Access Issue" echo " ๐Ÿ’ก RECOMMENDATION: Check file permissions, credentials, or access rights" elif echo "$JOB_LOGS" | grep -qi "timeout\|timed out"; then echo " โฑ๏ธ ROOT CAUSE: Timeout Issue" echo " ๐Ÿ’ก RECOMMENDATION: Increase timeout values or optimize job performance" elif echo "$JOB_LOGS" | grep -qi "dependency.*not found\|module.*not found\|package.*not found"; then echo " ๐Ÿ“ฆ ROOT CAUSE: Missing Dependency" echo " ๐Ÿ’ก RECOMMENDATION: Update dependencies, check package.json/requirements.txt" elif echo "$JOB_LOGS" | grep -qi "test.*failed\|assertion.*failed\|expected.*but got"; then echo " ๐Ÿงช ROOT CAUSE: Test Assertion Failure" echo " ๐Ÿ’ก RECOMMENDATION: Review failing test cases and fix application logic" elif echo "$JOB_LOGS" | grep -qi "compilation.*error\|build.*failed\|syntax.*error"; then echo " ๐Ÿ”จ ROOT CAUSE: Compilation/Build Error" echo " ๐Ÿ’ก RECOMMENDATION: Fix syntax errors or build configuration issues" elif echo "$JOB_LOGS" | grep -qi "out of memory\|memory.*exceeded"; then echo " ๐Ÿ’พ ROOT CAUSE: Memory Limitation" echo " ๐Ÿ’ก RECOMMENDATION: Increase memory allocation or optimize memory usage" elif echo "$JOB_LOGS" | grep -qi "network.*error\|connection.*failed\|host.*unreachable"; then echo " ๐ŸŒ ROOT CAUSE: Network Connectivity Issue" echo " ๐Ÿ’ก RECOMMENDATION: Check network configuration and external service availability" elif echo "$JOB_LOGS" | grep -qi "lint.*error\|format.*error\|style.*violation"; then echo " ๐Ÿ“ ROOT CAUSE: Code Quality/Style Issue" echo " ๐Ÿ’ก RECOMMENDATION: Run linter locally and fix code style violations" else echo " โ“ ROOT CAUSE: Unclassified Failure" echo " ๐Ÿ’ก RECOMMENDATION: Manual log review required" fi # Show relevant log excerpt echo "" echo "๐Ÿ“„ Relevant Log Excerpt (last 10 lines):" echo "$JOB_LOGS" | tail -10 | sed 's/^/ /' # Advanced analysis for deep mode if [ "$analysis_depth" = "deep" ]; then echo "" echo "๐Ÿ”ฌ Deep Analysis:" # Error frequency analysis ERROR_COUNT=$(echo "$JOB_LOGS" | grep -ci "error\|failed\|exception") WARNING_COUNT=$(echo "$JOB_LOGS" | grep -ci "warning\|warn") echo " Error mentions: $ERROR_COUNT" echo " Warning mentions: $WARNING_COUNT" # Extract specific error messages echo " Key error messages:" echo "$JOB_LOGS" | grep -i "error\|failed\|exception" | tail -5 | sed 's/^/ /' fi else echo " โš ๏ธ No logs available for analysis" fi echo "" echo "๐Ÿ”— Full logs command: glab ci trace $JOB_ID" fi fi done fi ``` ### Phase 4: Historical Pattern Analysis ```bash if [ "$historical_analysis" = "true" ]; then echo "" echo "๐Ÿ“ˆ Historical Pattern Analysis:" echo "===============================" # Use pipeline analyzer for pattern detection source .bmad-core/utils/pipeline-analyzer.md echo "๐Ÿ” Analyzing failure patterns across recent pipelines..." analyze_failure_patterns "$ANALYSIS_BRANCH" # Additional historical context echo "" echo "๐Ÿ“Š Recent Pipeline Health Trends:" calculate_pipeline_health "$ANALYSIS_BRANCH" fi ``` ### Phase 5: Environment and Configuration Analysis ```bash echo "" echo "โš™๏ธ Environment & Configuration Analysis:" echo "========================================" # Check CI configuration if [ -f ".gitlab-ci.yml" ]; then echo "๐Ÿ“‹ GitLab CI Configuration Status:" # Validate CI configuration CONFIG_VALIDATION=$(glab ci lint 2>/dev/null) if [ $? -eq 0 ]; then echo " โœ… .gitlab-ci.yml syntax is valid" else echo " โŒ .gitlab-ci.yml has syntax errors" echo " ๐Ÿ’ก RECOMMENDATION: Fix CI configuration syntax" fi # Analyze CI file for common issues echo "" echo "๐Ÿ” Configuration Analysis:" # Check for resource limitations if grep -q "memory\|cpu\|resources" .gitlab-ci.yml; then echo " โ„น๏ธ Resource constraints configured" else echo " โš ๏ธ No explicit resource constraints found" echo " ๐Ÿ’ก RECOMMENDATION: Consider adding resource limits to prevent resource-related failures" fi # Check for timeout configurations if grep -q "timeout" .gitlab-ci.yml; then echo " โ„น๏ธ Custom timeouts configured" else echo " โš ๏ธ Using default timeouts" echo " ๐Ÿ’ก RECOMMENDATION: Consider explicit timeout configuration for long-running jobs" fi else echo "โŒ No .gitlab-ci.yml found" echo " ๐Ÿ’ก RECOMMENDATION: Ensure CI configuration file exists and is properly named" fi # Check repository context echo "" echo "๐Ÿ“ Repository Context:" echo " Branch: $ANALYSIS_BRANCH" echo " Recent commits:" git log --oneline -5 | sed 's/^/ /' # Check for environment variables or secrets issues echo "" echo "๐Ÿ” Environment Analysis:" echo " ๐Ÿ’ก Common environment-related failure causes:" echo " - Missing required environment variables" echo " - Expired or invalid secrets/tokens" echo " - Incorrect environment-specific configurations" echo " ๐Ÿ” Review pipeline variables in GitLab project settings" ``` ### Phase 6: Integration Alerts and JIRA Updates ```bash if [ "$integration_alerts" = "true" ]; then echo "" echo "๐Ÿ”— Integration Alerts:" echo "====================" # Use integration bridge for cross-pack coordination source .bmad-core/utils/gitlab-integration-bridge.md # Detect integration opportunities detect_expansion_packs auto_detect_integration_context # JIRA integration for failure reporting if [ "$JIRA_INTEGRATION" = "true" ] && [ -n "$DETECTED_JIRA_ISSUES" ]; then echo "" echo "๐ŸŽฏ JIRA Integration Alert:" echo " Detected JIRA issues: $DETECTED_JIRA_ISSUES" echo " ๐Ÿ’ก RECOMMENDATION: Update JIRA issues with failure analysis" echo " ๐Ÿ”„ Creating JIRA-compatible failure report..." # Prepare JIRA failure report JIRA_FAILURE_REPORT="h3. โŒ CI Pipeline Failure Analysis *Branch:* $ANALYSIS_BRANCH *Pipeline ID:* $(echo "$PIPELINE_DATA" | jq -r '.id') *Failure Time:* $(date) h4. Failed Jobs: $(echo "$FAILED_JOBS" | while read job; do echo "* $job"; done) h4. Root Cause Analysis: See pipeline failure analysis for detailed investigation. *Pipeline URL:* [View Pipeline|$(echo "$PIPELINE_DATA" | jq -r '.web_url')] " echo " ๐Ÿ“ JIRA update prepared - use jira agent to apply" fi # Parallel development coordination if [ "$PARALLEL_DEV_INTEGRATION" = "true" ]; then echo "" echo "๐Ÿ”€ Parallel Development Alert:" echo " ๐Ÿ’ก This failure may block parallel development merge" echo " ๐Ÿ”„ Coordinating with other worktrees..." coordinate_parallel_ci fi fi ``` ### Phase 7: Failure Report Generation ```bash if [ "$generate_report" = "true" ]; then echo "" echo "๐Ÿ“„ Generating Comprehensive Failure Report:" echo "===========================================" REPORT_FILE="pipeline_failure_analysis_$(date +%Y%m%d_%H%M%S).md" # Generate detailed markdown report cat > "$REPORT_FILE" << EOF # Pipeline Failure Analysis Report **Generated:** $(date) **Branch:** $ANALYSIS_BRANCH **Pipeline ID:** $(echo "$PIPELINE_DATA" | jq -r '.id') **Analysis Depth:** $analysis_depth ## Executive Summary $(if [ -n "$FAILED_JOBS" ]; then echo "โŒ **Status:** Pipeline failed with $(echo "$FAILED_JOBS" | wc -l) failed job(s)" echo "" echo "**Failed Jobs:**" echo "$FAILED_JOBS" | while read job; do echo "- $job"; done else echo "โ„น๏ธ **Status:** Pipeline analysis completed (status: $PIPELINE_STATUS)" fi) ## Detailed Analysis ### Pipeline Overview - **ID:** $(echo "$PIPELINE_DATA" | jq -r '.id') - **Status:** $(echo "$PIPELINE_DATA" | jq -r '.status') - **Duration:** $(echo "$PIPELINE_DATA" | jq -r '.duration // 0')s - **Created:** $(echo "$PIPELINE_DATA" | jq -r '.created_at') - **URL:** $(echo "$PIPELINE_DATA" | jq -r '.web_url') ### Job Analysis $(echo "$PIPELINE_DATA" | jq -r '.jobs[] | "- **\(.name):** \(.status) (\(.stage)) - \(.duration // 0)s"') ## Recommendations $(if [ -n "$FAILED_JOBS" ]; then echo "### Immediate Actions" echo "1. ๐Ÿ” Review failed job logs using: \`glab ci trace <job-id>\`" echo "2. ๐Ÿ”ง Address root causes identified in analysis" echo "3. ๐Ÿ“ Update code and push fixes" echo "4. ๐Ÿ”„ Monitor new pipeline execution" echo "" echo "### Integration Actions" if [ "$JIRA_INTEGRATION" = "true" ]; then echo "- ๐ŸŽฏ Update JIRA issues with failure details" fi if [ "$PARALLEL_DEV_INTEGRATION" = "true" ]; then echo "- ๐Ÿ”€ Coordinate with parallel development team" fi else echo "### General Recommendations" echo "- โœ… Pipeline appears healthy" echo "- ๐Ÿ”„ Continue with normal development workflow" fi) ## Technical Details ### Environment Context - **Repository:** $(git remote get-url origin 2>/dev/null || echo "Local repository") - **Branch:** $ANALYSIS_BRANCH - **Recent Commits:** $(git log --oneline -3 | sed 's/^/ /') --- *Report generated by GitLab CI/CD Automation - analyze-pipeline-failures task* EOF echo "๐Ÿ“„ Report saved: $REPORT_FILE" echo "๐Ÿ“Š Report contains comprehensive failure analysis and recommendations" fi ``` ### Phase 8: Next Steps and Recovery Guidance ```bash echo "" echo "๐ŸŽฏ Next Steps & Recovery Guidance:" echo "=================================" if [ -n "$FAILED_JOBS" ]; then echo "๐Ÿšจ IMMEDIATE ACTIONS REQUIRED:" echo "" echo "1. ๐Ÿ” INVESTIGATE - Review the root cause analysis above" echo "2. ๐Ÿ”ง FIX - Address identified issues in your code" echo "3. ๐Ÿ“ COMMIT - Push fixes to trigger new pipeline" echo "4. ๐Ÿ”„ MONITOR - Watch new pipeline execution" if [ "$JIRA_INTEGRATION" = "true" ] && [ -n "$DETECTED_JIRA_ISSUES" ]; then echo "5. ๐ŸŽฏ UPDATE JIRA - Inform stakeholders of resolution progress" fi echo "" echo "๐Ÿ”ง COMMON QUICK FIXES:" echo "- Permission issues: Check file permissions and access credentials" echo "- Dependency issues: Update package.json, requirements.txt, or similar" echo "- Test failures: Review and fix failing test cases" echo "- Build errors: Fix syntax errors and compilation issues" echo "- Timeout issues: Optimize job performance or increase timeout limits" else echo "โœ… NO IMMEDIATE ACTIONS REQUIRED" echo "" echo "๐Ÿ“ˆ OPTIMIZATION OPPORTUNITIES:" echo "- Review pipeline performance for optimization" echo "- Consider adding more comprehensive tests" echo "- Evaluate CI/CD configuration for improvements" fi echo "" echo "๐Ÿ†˜ NEED HELP?" echo "- Review full job logs: glab ci trace <job-id>" echo "- Check GitLab project CI/CD settings" echo "- Consult team DevOps guidelines" echo "- Use glab agent for interactive assistance" echo "" echo "โœ… ANALYSIS COMPLETE" echo "๐Ÿ“Š Use the generated insights to improve pipeline reliability" ``` --- ## Integration Hooks ### JIRA Integration Points - Automatic bug report creation for pipeline failures - Failure analysis details added to JIRA comments - Status updates for development progress tracking ### Parallel Development Integration Points - Failure impact assessment across worktrees - Merge blocking alerts for failed pipelines - Coordination recommendations for team workflow ### Core BMAD Integration Points - Failure analysis integration with development workflows - Root cause insights for architecture decisions - Quality gate integration for story completion criteria --- ## Success Criteria - โœ… Successfully identifies and categorizes all pipeline failures - โœ… Provides accurate root cause analysis with actionable recommendations - โœ… Integrates failure alerts with available expansion packs - โœ… Generates comprehensive failure reports for documentation - โœ… Operates autonomously with intelligent pattern recognition - โœ… Delivers clear next steps for failure resolution ## Dependencies - **GitLab CLI** (`glab`) with authentication - **Utilities**: ci-status-parser, pipeline-analyzer, gitlab-integration-bridge - **Optional**: JIRA integration, parallel-dev integration - **Git repository** with GitLab remote and CI configuration