修改sonarQube配置和docker配置

This commit is contained in:
wangtianqi 2025-06-25 15:33:38 +08:00
parent fa853ce01d
commit dfe8f165c4
2 changed files with 19 additions and 16 deletions

View File

@ -17,9 +17,6 @@ WORKDIR /app
# 直接复制已构建的二进制文件在Jenkins中已经通过go build构建完成
COPY golang-demo .
# 复制配置文件(如果存在)
COPY .env* ./
# 创建日志目录并设置权限
RUN mkdir -p /app/logs && chown -R goapp:goapp /app && chmod +x /app/golang-demo

30
Jenkinsfile vendored
View File

@ -9,6 +9,8 @@ pipeline {
tools {
go 'go' // 使用Jenkins手动配置的Go工具
// 添加SonarQube Scanner工具
sonarQubeScanner 'sonarQube'
}
environment {
@ -150,26 +152,30 @@ pipeline {
echo '🔍 运行SonarQube代码扫描...'
script {
try {
// 使用sonar-scanner for Go项目
sh """
# 创建sonar-project.properties文件
cat > sonar-project.properties << EOF
// 创建SonarQube配置文件
writeFile file: 'sonar-project.properties', text: """
sonar.projectKey=${SONAR_PROJECT_KEY}
sonar.projectName=golang-demo
sonar.projectVersion=1.0.0
sonar.projectName=Golang Demo
sonar.projectVersion=${BUILD_NUMBER}
sonar.sources=.
sonar.exclusions=vendor/**,**/*_test.go,**/testdata/**
sonar.exclusions=**/*_test.go,**/vendor/**,**/*.mod,**/*.sum
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**
sonar.go.coverage.reportPaths=coverage.out
sonar.host.url=${SONAR_HOST_URL}
sonar.login=${SONAR_TOKEN}
EOF
sonar.sourceEncoding=UTF-8
sonar.language=go
"""
# 运行sonar-scanner
sonar-scanner || echo "SonarQube扫描工具未安装跳过扫描"
// 使用Jenkins配置的SonarQube Scanner工具
sh """
sonar-scanner \
-Dsonar.projectKey=${SONAR_PROJECT_KEY} \
-Dsonar.host.url=${SONAR_HOST_URL} \
-Dsonar.login=${SONAR_TOKEN}
"""
echo "✅ SonarQube代码扫描完成"
} catch (Exception e) {
echo "⚠️ SonarQube扫描失败继续构建流程: ${e.getMessage()}"
}