pipeline { agent any options { ansiColor('xterm') disableConcurrentBuilds() } stages { stage('Setup') { steps { echo '๐Ÿ”ง Verifying Rust environment...' sh ''' rustc --version cargo --version ''' } } stage('Install Tools') { steps { echo '๐Ÿ“ฆ Installing test tools...' sh ''' if ! command -v cargo-nextest &> /dev/null; then cargo install cargo-nextest fi if ! command -v cargo-llvm-cov &> /dev/null; then cargo install cargo-llvm-cov fi if ! command -v cargo-audit &> /dev/null; then cargo install cargo-audit fi rustup component add llvm-tools-preview ''' } } stage('Security Audit') { steps { echo '๐Ÿ”’ Running cargo audit...' sh ''' cargo audit --json > audit-report.json || true ''' } } stage('Check Code') { steps { echo '๐Ÿ” Running cargo check...' sh ''' cargo check --message-format json > cargo-check.log || true ''' } } stage('Run Tests with Coverage') { steps { echo '๐Ÿงช Running tests with coverage...' sh ''' # Run tests with nextest and generate JUnit cargo nextest run --profile ci --verbose || true # Create coverage directory and generate coverage mkdir -p coverage cargo llvm-cov nextest --cobertura --output-path coverage/cobertura.xml || true ''' } } stage('Generate Docs') { steps { echo '๐Ÿ“š Generating documentation...' sh ''' cargo doc --no-deps || true ''' } } stage('Publish Results') { steps { echo '๐Ÿ“‹ Publishing test results, coverage, and warnings...' junit allowEmptyResults: true, testResults: 'target/nextest/ci/junit.xml' recordCoverage(tools: [[parser: 'COBERTURA', pattern: '**/cobertura.xml']]) recordIssues tool: cargo(pattern: 'cargo-check.log') echo '๐Ÿ“š Publishing documentation...' publishHTML(target: [ allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true, reportDir: 'target/doc', reportFiles: 'crud_pricing/index.html', reportName: 'Rust Documentation' ]) } } } post { always { echo '๐Ÿงน Archiving artifacts...' archiveArtifacts artifacts: 'coverage/**/*.xml, target/nextest/**/*.xml, cargo-check.log, audit-report.json', allowEmptyArchive: true } success { echo 'โœ… Build completed!' } unstable { echo 'โš ๏ธ Build unstable - some tests may have failed' } failure { echo 'โŒ Build failed!' } } }