修复 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 {
sh '''
docker run --rm \
-u $(id -u):$(id -g) \
-e HOME=/tmp \
-v "$WORKSPACE":/workspace \
-w /workspace \
node:20-bookworm \
sh -lc "npm ci"
docker pull node:20-bookworm
docker pull mcr.microsoft.com/playwright:v1.51.1-jammy
'''
}
}
@@ -39,13 +34,11 @@ pipeline {
stage('Quality Gate') {
steps {
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"
set -e
cid=$(docker create node:20-bookworm sh -lc "cd /workspace && npm ci && npm run lint && npx tsc --noEmit && npm run test:coverage")
trap 'docker rm -f "$cid" >/dev/null 2>&1 || true' EXIT
docker cp . "$cid":/workspace
docker start -a "$cid"
'''
}
}
@@ -56,14 +49,20 @@ pipeline {
}
steps {
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"
set -e
cid=$(docker create --ipc=host mcr.microsoft.com/playwright:v1.51.1-jammy sh -lc "cd /workspace && npm ci && npm run test:e2e")
cleanup() {
docker rm -f "$cid" >/dev/null 2>&1 || true
}
trap cleanup EXIT
docker cp . "$cid":/workspace
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 {