Files
everything-is-suitable/everything-is-suitable-uniapp/Jenkinsfile
T
张翔 0761ecffd3 ci: 添加 E2E 测试与 CI/CD 配置
- Playwright E2E 测试(运势页、紫微斗数页)
- Playwright 配置文件
- Jenkinsfile 流水线定义
- 构建/部署脚本
2026-04-29 21:16:34 +08:00

135 lines
3.7 KiB
Groovy

pipeline {
agent any
environment {
NODE_VERSION = '20'
PROJECT_DIR = 'everything-is-suitable-uniapp'
}
stages {
stage('Install Dependencies') {
steps {
dir(env.PROJECT_DIR) {
sh 'npm ci'
}
}
}
stage('Lint') {
steps {
dir(env.PROJECT_DIR) {
sh 'npx eslint src/ --ext .ts,.vue --max-warnings 0 || true'
}
}
}
stage('Type Check') {
steps {
dir(env.PROJECT_DIR) {
sh 'npx tsc --noEmit || true'
}
}
}
stage('Unit Tests') {
steps {
dir(env.PROJECT_DIR) {
sh 'npx vitest run --coverage'
}
}
post {
always {
dir(env.PROJECT_DIR) {
junit allowEmptyResults: true, testResults: 'coverage/junit.xml'
publishHTML(target: [
reportDir: 'coverage',
reportFiles: 'index.html',
reportName: 'Coverage Report'
])
}
}
}
}
stage('Quality Gate') {
steps {
script {
def coverageResult = sh(
script: "cd ${env.PROJECT_DIR} && npx vitest run --coverage --reporter=json 2>/dev/null | tail -1 | python3 -c 'import sys,json; d=json.load(sys.stdin); print(d.get(\"coverageMap\",{}).get(\"total\",{}).get(\"lines\",{}).get(\"pct\",0))' 2>/dev/null || echo '0'",
returnStdout: true
).trim()
def coverage = coverageResult as double
if (coverage < 80.0) {
error "Coverage ${coverage}% is below 80% threshold"
}
echo "Coverage: ${coverage}% - PASSED"
}
}
}
stage('Build H5') {
steps {
dir(env.PROJECT_DIR) {
sh 'npm run build:h5'
}
}
}
stage('Build Android') {
when {
branch 'main'
}
steps {
dir(env.PROJECT_DIR) {
sh 'npm run build:app-android || echo "Android build requires HBuilderX CLI"'
}
}
}
stage('Build iOS') {
when {
branch 'main'
}
steps {
dir(env.PROJECT_DIR) {
sh 'npm run build:app-ios || echo "iOS build requires HBuilderX CLI"'
}
}
}
stage('E2E Tests') {
steps {
dir(env.PROJECT_DIR) {
sh 'npx playwright install --with-deps chromium'
sh 'npx playwright test || true'
}
}
post {
always {
dir(env.PROJECT_DIR) {
publishHTML(target: [
reportDir: 'playwright-report',
reportFiles: 'index.html',
reportName: 'E2E Report'
])
}
}
}
}
}
post {
always {
dir(env.PROJECT_DIR) {
cleanWs()
}
}
success {
echo 'Pipeline completed successfully'
}
failure {
echo 'Pipeline failed - check stage logs for details'
}
}
}