Update JK

This commit is contained in:
Anupong Hompan 2025-10-21 08:35:51 +07:00
parent b02408abc0
commit 5df9aede66

43
Jenkinsfile vendored
View File

@ -18,8 +18,8 @@ pipeline {
DC_DATA = "${JENKINS_HOME}/.dc-cache" DC_DATA = "${JENKINS_HOME}/.dc-cache"
// ถ้าจะใช้ SonarQube ให้ตั้งค่าตามระบบจริง // ถ้าจะใช้ SonarQube ให้ตั้งค่าตามระบบจริง
// SONAR_HOST_URL = 'http://sonarqube:9000' SONARQUBE_INSTANCE = 'SonarQube'
// SONAR_TOKEN = credentials('SONAR_TOKEN') SONAR_PROJECT_KEY = 'AS400API'
} }
stages { stages {
@ -125,34 +125,45 @@ pipeline {
stage('SAST') { stage('SAST') {
steps { steps {
sh ''' script {
if (env.SONARQUBE_INSTANCE?.trim()) {
withSonarQubeEnv(env.SONARQUBE_INSTANCE) {
sh """
set -euo pipefail set -euo pipefail
if [ -n "${SONAR_HOST_URL:-}" ] && [ -n "${SONAR_TOKEN:-}" ]; then echo "=== SAST with SonarQube (${env.SONARQUBE_INSTANCE}) ==="
echo "=== SAST with SonarQube ==="
# ถ้าใช้ sonarscanner for .NET (แนะนำ)
dotnet tool update --global dotnet-sonarscanner || dotnet tool install --global dotnet-sonarscanner dotnet tool update --global dotnet-sonarscanner || dotnet tool install --global dotnet-sonarscanner
export PATH="$HOME/.dotnet/tools:${PATH}" export PATH="$HOME/.dotnet/tools:${PATH}"
dotnet-sonarscanner begin \ dotnet clean -c Release
/k:"AS400API" \
/d:sonar.host.url="${SONAR_HOST_URL}" \
/d:sonar.login="${SONAR_TOKEN}"
dotnet build -c Release dotnet sonarscanner begin \
/k:"${env.SONAR_PROJECT_KEY}" \
/d:sonar.host.url="\$SONAR_HOST_URL" \
/d:sonar.login="\$SONAR_AUTH_TOKEN"
dotnet-sonarscanner end /d:sonar.login="${SONAR_TOKEN}"
else
echo "=== SAST with Roslyn analyzers (no Sonar) ==="
# เปิด .NET analyzers และ treat warnings เป็น error
dotnet build -c Release \ dotnet build -c Release \
-p:EnableNETAnalyzers=true \ -p:EnableNETAnalyzers=true \
-p:TreatWarningsAsErrors=true \ -p:TreatWarningsAsErrors=true \
-warnaserror -warnaserror
fi
dotnet sonarscanner end /d:sonar.login="\$SONAR_AUTH_TOKEN"
"""
}
} else {
sh '''
set -euo pipefail
echo "=== SAST with Roslyn analyzers (no Sonar) ==="
dotnet clean -c Release
dotnet build -c Release \
-p:EnableNETAnalyzers=true \
-p:TreatWarningsAsErrors=true \
-warnaserror
''' '''
} }
} }
}
}
stage('Test + Coverage') { stage('Test + Coverage') {
steps { steps {