fix: Jenkinsfile 适配无 Node.js 环境

- 通过 nvm 安装 Node.js(Jenkins 容器内无预装)
- 所有 sh 步骤 source nvm 确保 node/pnpm 可用
- cleanWs() 替换为 deleteDir()(ws-cleanup 插件未安装)
This commit is contained in:
xiangning 2026-05-11 02:37:14 +08:00
parent 24f4abde20
commit cc5f5f587b

36
Jenkinsfile vendored
View File

@ -3,30 +3,42 @@ pipeline {
environment { environment {
NODE_VERSION = '22' NODE_VERSION = '22'
PNPM_VERSION = '10' NVM_DIR = "$HOME/.nvm"
} }
stages { stages {
stage('Setup Node.js') {
steps {
sh '''
if ! command -v node &> /dev/null; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
. "$NVM_DIR/nvm.sh"
nvm install $NODE_VERSION
nvm use $NODE_VERSION
fi
. "$NVM_DIR/nvm.sh"
node -v
npm install -g pnpm@10
pnpm -v
'''
}
}
stage('Install') { stage('Install') {
steps { steps {
sh ''' sh '''
if ! command -v pnpm &> /dev/null; then . "$NVM_DIR/nvm.sh"
npm install -g pnpm@${PNPM_VERSION}
fi
pnpm install --frozen-lockfile pnpm install --frozen-lockfile
''' '''
} }
} }
stage('Lint') {
steps {
sh 'pnpm run lint || true'
}
}
stage('Build') { stage('Build') {
steps { steps {
sh 'pnpm run build:antd' sh '''
. "$NVM_DIR/nvm.sh"
pnpm run build:antd
'''
} }
} }
@ -45,7 +57,7 @@ pipeline {
echo 'Frontend build failed!' echo 'Frontend build failed!'
} }
always { always {
cleanWs() deleteDir()
} }
} }
} }