Jenkinsfile 1.29 KB
pipeline {
    agent any
    
    tools {
        maven 'maven-3.8'
    }
    
    stages {
        stage('SonarQube Analysis') {
            steps {
                withSonarQubeEnv('sonarqube') {
                    sh 'mvn clean compile sonar:sonar'
                }
            }
        }
        
        stage('Quality Gate Check') {
            steps {
                script {
                    try {
                        timeout(time: 15, unit: 'MINUTES') {
                            waitForQualityGate abortPipeline: false
                        }
                    } catch (Exception e) {
                        echo "⚠️  SonarQube 质量门控检查超时,继续执行构建"
                    }
                }
            }
        }
        
        stage('Build & Test') {
            steps {
                sh 'mvn test'
            }
            
            post {
                always {
                    junit 'target/surefire-reports/*.xml'
                }
            }
        }
    }
    
    post {
        always {
            echo "Allen的计算器项目构建完成 - 构建号: ${BUILD_NUMBER}"
        }
        success {
            echo "✅ 构建成功!"
        }
        failure {
            echo "❌ 构建失败,请检查日志"
        }
    }
}