fix: 修复Jenkinsfile语法错误和缩进问题

- 修复stages缩进错误
- 修复stage之间缺少换行的问题
- 修复script块中的格式错误
- 确保所有stage都有正确的缩进
This commit is contained in:
wangtianqi 2025-06-23 20:27:15 +08:00
parent 76e1b34f4a
commit 0725abdcb4

31
Jenkinsfile vendored
View File

@ -21,14 +21,14 @@ pipeline {
SONAR_HOST_URL = 'http://116.62.163.84:15010' SONAR_HOST_URL = 'http://116.62.163.84:15010'
SONAR_PROJECT_KEY = 'jenkins-demo' SONAR_PROJECT_KEY = 'jenkins-demo'
SONAR_TOKEN = 'squ_7e4217cabd0faae6f3b8ee359b3b8e2ac52eb69a' SONAR_TOKEN = 'squ_7e4217cabd0faae6f3b8ee359b3b8e2ac52eb69a'
} }
// 使用Jenkins中配置的工具自动安装 // 使用Jenkins中配置的工具自动安装
tools { tools {
maven 'Maven-3.9.6' // 使用您在Jenkins中配置的Maven名称 maven 'Maven-3.9.6' // 使用您在Jenkins中配置的Maven名称
// JDK使用容器中已有的不需要额外配置 // JDK使用容器中已有的不需要额外配置
} }
stages {
stages {
stage('Checkout') { stage('Checkout') {
steps { steps {
echo '🔄 开始检出代码...' echo '🔄 开始检出代码...'
@ -39,11 +39,12 @@ pipeline {
script: "git rev-parse --short HEAD", script: "git rev-parse --short HEAD",
returnStdout: true returnStdout: true
).trim() ).trim()
} }
echo "📋 Git提交ID: ${env.GIT_COMMIT_SHORT}" echo "📋 Git提交ID: ${env.GIT_COMMIT_SHORT}"
} }
} stage('环境检查') { }
stage('环境检查') {
steps { steps {
echo '🔍 检查构建环境...' echo '🔍 检查构建环境...'
script { script {
@ -65,9 +66,9 @@ pipeline {
env.MVN_CMD = 'mvn' env.MVN_CMD = 'mvn'
echo "✅ 构建环境检查完成Maven命令: ${env.MVN_CMD}" echo "✅ 构建环境检查完成Maven命令: ${env.MVN_CMD}"
} }
} } }
}
stage('编译') { stage('编译') {
steps { steps {
echo '🔨 开始编译项目...' echo '🔨 开始编译项目...'
sh "mvn clean compile -DskipTests=true" sh "mvn clean compile -DskipTests=true"
@ -101,10 +102,10 @@ pipeline {
} }
} }
stage('代码质量扫描') { stage('代码质量扫描') { steps {
steps {
echo '🔍 运行SonarQube代码扫描...' echo '🔍 运行SonarQube代码扫描...'
script { try { script {
try {
sh """ sh """
mvn sonar:sonar \ mvn sonar:sonar \
-Dsonar.projectKey=${SONAR_PROJECT_KEY} \ -Dsonar.projectKey=${SONAR_PROJECT_KEY} \
@ -118,9 +119,9 @@ pipeline {
echo "⚠️ SonarQube扫描失败继续构建流程: ${e.getMessage()}" echo "⚠️ SonarQube扫描失败继续构建流程: ${e.getMessage()}"
} }
} }
} } }
}
stage('打包') { stage('打包') {
steps { steps {
echo '📦 开始打包应用程序...' echo '📦 开始打包应用程序...'
sh "mvn package -DskipTests=true" sh "mvn package -DskipTests=true"