Jenkins 改为容器化执行 Node 质量门禁与 E2E

This commit is contained in:
2026-03-03 15:13:50 +08:00
parent 17cf80bed3
commit f892c92608
Vendored
+30 -22
View File
@@ -16,35 +16,37 @@ pipeline {
} }
} }
stage('Node Runtime') { stage('Runtime Check') {
steps { steps {
script { sh 'docker --version'
if (sh(returnStatus: true, script: 'command -v npm >/dev/null 2>&1') != 0) {
echo "System npm not found, trying Jenkins NodeJS tool 'node20'"
try {
def nodeHome = tool name: 'node20', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
env.PATH = "${nodeHome}/bin:${env.PATH}"
} catch (err) {
error "npm not found and Jenkins NodeJS tool 'node20' is unavailable. Please install NodeJS plugin and configure tool name 'node20'. Root cause: ${err}"
}
}
}
sh 'node -v'
sh 'npm -v'
} }
} }
stage('Install Dependencies') { stage('Install Dependencies') {
steps { steps {
sh 'npm ci' sh '''
docker run --rm \
-u $(id -u):$(id -g) \
-e HOME=/tmp \
-v "$WORKSPACE":/workspace \
-w /workspace \
node:20-bookworm \
sh -lc "npm ci"
'''
} }
} }
stage('Quality Gate') { stage('Quality Gate') {
steps { steps {
sh 'npm run lint' sh '''
sh 'npx tsc --noEmit' docker run --rm \
sh 'npm run test:coverage' -u $(id -u):$(id -g) \
-e HOME=/tmp \
-v "$WORKSPACE":/workspace \
-w /workspace \
node:20-bookworm \
sh -lc "npm run lint && npx tsc --noEmit && npm run test:coverage"
'''
} }
} }
@@ -53,10 +55,16 @@ pipeline {
timeout(time: 20, unit: 'MINUTES') timeout(time: 20, unit: 'MINUTES')
} }
steps { steps {
retry(2) { sh '''
sh 'npm run test:e2e:install' docker run --rm \
} --ipc=host \
sh 'npm run test:e2e' -u $(id -u):$(id -g) \
-e HOME=/tmp \
-v "$WORKSPACE":/workspace \
-w /workspace \
mcr.microsoft.com/playwright:v1.51.1-jammy \
sh -lc "npm run test:e2e"
'''
} }
post { post {
always { always {