From 789234b52fcff178610de94eec4b7b8abfad54e8 Mon Sep 17 00:00:00 2001 From: caoyuchun <335003032@qq.com> Date: Tue, 20 Jan 2026 13:35:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9jenkins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2ce4ad0..a7a5367 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,19 +21,53 @@ pipeline { } } + stage('Test Node.js') { + steps { + echo '测试 Node.js 环境...' + sh ''' + # 检查 Node.js 是否安装 + if ! command -v node &> /dev/null; then + echo "❌ 错误: Node.js 未安装,请安装 Node.js 22+" + exit 1 + fi + + # 获取版本信息 + NODE_VERSION=$(node --version) + NPM_VERSION=$(npm --version) + NODE_PATH=$(which node) + NPM_PATH=$(which npm) + + # 显示版本信息 + echo "==========================================" + echo "Node.js 环境信息" + echo "==========================================" + echo "Node 版本: $NODE_VERSION" + echo "NPM 版本: $NPM_VERSION" + echo "Node 路径: $NODE_PATH" + echo "NPM 路径: $NPM_PATH" + echo "==========================================" + + # 检查 Node.js 版本是否符合要求(22+) + NODE_MAJOR_VERSION=$(echo $NODE_VERSION | sed 's/v//' | cut -d. -f1) + if [ "$NODE_MAJOR_VERSION" -lt 22 ]; then + echo "❌ 错误: Node.js 版本过低,需要 22+,当前版本: $NODE_VERSION" + exit 1 + fi + + echo "✅ Node.js 版本检查通过: $NODE_VERSION" + + # 测试基本命令 + echo "测试 Node.js 和 NPM 命令..." + node --version > /dev/null && echo "✅ node 命令正常" || (echo "❌ node 命令失败" && exit 1) + npm --version > /dev/null && echo "✅ npm 命令正常" || (echo "❌ npm 命令失败" && exit 1) + ''' + } + } + stage('Build') { steps { echo '构建项目...' sh ''' - # 检查 Node.js - if ! command -v node &> /dev/null; then - echo "错误: Node.js 未安装,请安装 Node.js 22+" - exit 1 - fi - - echo "Node 版本: $(node --version)" - echo "NPM 版本: $(npm --version)" - # 安装依赖 echo "安装依赖..." npm install