修复 Jenkins 容器内看不到 lockfile 的问题

This commit is contained in:
2026-03-03 15:17:53 +08:00
parent f892c92608
commit 35aa7fb6bc
Vendored
+22 -23
View File
@@ -22,16 +22,11 @@ pipeline {
} }
} }
stage('Install Dependencies') { stage('Prepare Test Images') {
steps { steps {
sh ''' sh '''
docker run --rm \ docker pull node:20-bookworm
-u $(id -u):$(id -g) \ docker pull mcr.microsoft.com/playwright:v1.51.1-jammy
-e HOME=/tmp \
-v "$WORKSPACE":/workspace \
-w /workspace \
node:20-bookworm \
sh -lc "npm ci"
''' '''
} }
} }
@@ -39,13 +34,11 @@ pipeline {
stage('Quality Gate') { stage('Quality Gate') {
steps { steps {
sh ''' sh '''
docker run --rm \ set -e
-u $(id -u):$(id -g) \ cid=$(docker create node:20-bookworm sh -lc "cd /workspace && npm ci && npm run lint && npx tsc --noEmit && npm run test:coverage")
-e HOME=/tmp \ trap 'docker rm -f "$cid" >/dev/null 2>&1 || true' EXIT
-v "$WORKSPACE":/workspace \ docker cp . "$cid":/workspace
-w /workspace \ docker start -a "$cid"
node:20-bookworm \
sh -lc "npm run lint && npx tsc --noEmit && npm run test:coverage"
''' '''
} }
} }
@@ -56,14 +49,20 @@ pipeline {
} }
steps { steps {
sh ''' sh '''
docker run --rm \ set -e
--ipc=host \ cid=$(docker create --ipc=host mcr.microsoft.com/playwright:v1.51.1-jammy sh -lc "cd /workspace && npm ci && npm run test:e2e")
-u $(id -u):$(id -g) \ cleanup() {
-e HOME=/tmp \ docker rm -f "$cid" >/dev/null 2>&1 || true
-v "$WORKSPACE":/workspace \ }
-w /workspace \ trap cleanup EXIT
mcr.microsoft.com/playwright:v1.51.1-jammy \ docker cp . "$cid":/workspace
sh -lc "npm run test:e2e" set +e
docker start -a "$cid"
status=$?
set -e
docker cp "$cid":/workspace/playwright-report ./playwright-report 2>/dev/null || true
docker cp "$cid":/workspace/test-results ./test-results 2>/dev/null || true
exit $status
''' '''
} }
post { post {