Skip to content

Commit 1dfc345

Browse files
authored
move Sonar scan from GitHub Action to Jenkinsfile (#352)
1 parent fc8fce6 commit 1dfc345

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

Jenkinsfile

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ pipeline {
9999
}
100100
}
101101
}
102+
stage ('Analyze') {
103+
when {
104+
anyOf {
105+
changeRequest()
106+
branch "main"
107+
}
108+
}
109+
tools {
110+
maven 'maven-3.6.0'
111+
jdk 'jdk11'
112+
}
113+
steps {
114+
withSonarQubeEnv('SonarCloud') {
115+
withCredentials([string(credentialsId: 'encj_github_token', variable: 'GITHUB_TOKEN')]) {
116+
runSonarScanner()
117+
}
118+
}
119+
}
120+
}
102121
stage ('Save Nightly Installer'){
103122
when {
104123
allOf {
@@ -113,4 +132,23 @@ pipeline {
113132
}
114133
}
115134
}
116-
}
135+
}
136+
137+
void runSonarScanner() {
138+
def changeUrl = env.GIT_URL.split("/")
139+
def org = changeUrl[3]
140+
def repo = changeUrl[4].substring(0, changeUrl[4].length() - 4)
141+
if (env.CHANGE_ID != null) {
142+
sh "mvn -B sonar:sonar \
143+
-Dsonar.projectKey=${org}_${repo} \
144+
-Dsonar.pullrequest.provider=GitHub \
145+
-Dsonar.pullrequest.github.repository=${org}/${repo} \
146+
-Dsonar.pullrequest.key=${env.CHANGE_ID} \
147+
-Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} \
148+
-Dsonar.pullrequest.base=${env.CHANGE_TARGET}"
149+
} else {
150+
sh "mvn -B sonar:sonar \
151+
-Dsonar.projectKey=${org}_${repo} \
152+
-Dsonar.branch.name=${env.BRANCH_NAME}"
153+
}
154+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@
260260
<plugin>
261261
<groupId>org.jacoco</groupId>
262262
<artifactId>jacoco-maven-plugin</artifactId>
263-
<version>0.8.5</version>
263+
<version>0.8.7</version>
264264
</plugin>
265265
<plugin>
266266
<groupId>org.sonarsource.scanner.maven</groupId>

0 commit comments

Comments
 (0)