Jenkins 改为容器化执行 Node 质量门禁与 E2E
This commit is contained in:
Vendored
+30
-22
@@ -16,35 +16,37 @@ pipeline {
|
||||
}
|
||||
}
|
||||
|
||||
stage('Node Runtime') {
|
||||
stage('Runtime Check') {
|
||||
steps {
|
||||
script {
|
||||
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'
|
||||
sh 'docker --version'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Install Dependencies') {
|
||||
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') {
|
||||
steps {
|
||||
sh 'npm run lint'
|
||||
sh 'npx tsc --noEmit'
|
||||
sh 'npm run test:coverage'
|
||||
sh '''
|
||||
docker run --rm \
|
||||
-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')
|
||||
}
|
||||
steps {
|
||||
retry(2) {
|
||||
sh 'npm run test:e2e:install'
|
||||
}
|
||||
sh 'npm run test:e2e'
|
||||
sh '''
|
||||
docker run --rm \
|
||||
--ipc=host \
|
||||
-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 {
|
||||
always {
|
||||
|
||||
Reference in New Issue
Block a user