Skip to content

Commit 2497e56

Browse files
authored
added Sonar step to Jenkinsfile (#1103)
1 parent d3ce730 commit 2497e56

File tree

4 files changed

+52
-65
lines changed

4 files changed

+52
-65
lines changed

.github/workflows/build.yml

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

Jenkinsfile

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ pipeline {
1313
jdk 'jdk8'
1414
}
1515
steps {
16-
sh '''
17-
echo "PATH = ${PATH}"
18-
echo "JAVA_HOME = ${JAVA_HOME}"
19-
echo "M2_HOME = ${M2_HOME}"
20-
mvn --version
21-
'''
16+
sh 'env|sort'
2217
}
2318
}
2419
stage ('Build') {
@@ -42,7 +37,7 @@ pipeline {
4237
}
4338
}
4439
steps {
45-
sh 'mvn -Dunit-test-wlst-dir=${WLST_DIR} test'
40+
sh 'mvn -B -Dunit-test-wlst-dir=${WLST_DIR} test'
4641
}
4742
post {
4843
always {
@@ -67,15 +62,34 @@ pipeline {
6762
}
6863
}
6964
steps {
70-
sh 'mvn -DskipITs=false -Dmw_home=${ORACLE_HOME} -Ddb.use.container.network=true verify'
65+
sh 'mvn -B -DskipITs=false -Dmw_home=${ORACLE_HOME} -Ddb.use.container.network=true verify'
7166
}
7267
post {
7368
always {
7469
junit 'system-test/target/failsafe-reports/*.xml'
7570
}
7671
}
7772
}
78-
stage ('Alias Test') {
73+
stage ('Analyze') {
74+
when {
75+
anyOf {
76+
changeRequest()
77+
branch "main"
78+
}
79+
}
80+
tools {
81+
maven 'maven-3.6.0'
82+
jdk 'jdk11'
83+
}
84+
steps {
85+
withSonarQubeEnv('SonarCloud') {
86+
withCredentials([string(credentialsId: 'encj_github_token', variable: 'GITHUB_TOKEN')]) {
87+
runSonarScanner()
88+
}
89+
}
90+
}
91+
}
92+
stage ('Alias Test') {
7993
// only run this stage when triggered by a cron timer and the commit does not have []skip-ci in the message
8094
// for example, only run integration tests during the timer triggered nightly build
8195
when {
@@ -129,6 +143,24 @@ pipeline {
129143
'''
130144
}
131145
}
146+
}
147+
}
132148

149+
void runSonarScanner() {
150+
def changeUrl = env.CHANGE_URL.split("/")
151+
def org = changeUrl[3]
152+
def repo = changeUrl[4]
153+
if (changeRequest()) {
154+
sh "mvn -B sonar:sonar \
155+
-Dsonar.projectKey=${org}_${repo} \
156+
-Dsonar.pullrequest.provider=GitHub \
157+
-Dsonar.pullrequest.github.repository=${org}/${repo} \
158+
-Dsonar.pullrequest.key=${env.CHANGE_ID} \
159+
-Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} \
160+
-Dsonar.pullrequest.base=${env.CHANGE_TARGET}"
161+
} else {
162+
sh "mvn -B sonar:sonar \
163+
-Dsonar.projectKey=${org}_${repo} \
164+
-Dsonar.branch.name=${env.BRANCH_NAME}"
133165
}
134166
}

core/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
</resource>
8989
</resources>
9090
<plugins>
91+
<plugin>
92+
<groupId>org.jacoco</groupId>
93+
<artifactId>jacoco-maven-plugin</artifactId>
94+
</plugin>
9195
<plugin>
9296
<groupId>org.apache.maven.plugins</groupId>
9397
<artifactId>maven-jar-plugin</artifactId>
@@ -163,10 +167,6 @@
163167
<groupId>org.codehaus.mojo</groupId>
164168
<artifactId>flatten-maven-plugin</artifactId>
165169
</plugin>
166-
<plugin>
167-
<groupId>org.jacoco</groupId>
168-
<artifactId>jacoco-maven-plugin</artifactId>
169-
</plugin>
170170
</plugins>
171171
</build>
172172
</project>

pom.xml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@
5151
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
5252
<sonar.sources>src/main</sonar.sources>
5353
<sonar.java.source>7</sonar.java.source>
54+
<sonar.python.version>2</sonar.python.version>
5455
<sonar.exclusions>.flattened-pom.xml,target/**</sonar.exclusions>
55-
<sonar.test.exclusions>src/test/**</sonar.test.exclusions>
56+
<sonar.test.exclusions>core/src/test/**</sonar.test.exclusions>
57+
<sonar.coverage.jacoco.xmlReportPaths>core/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
58+
5659
<unit-test-wlst-dir>${env.WLST_DIR}</unit-test-wlst-dir>
5760
<skipITs>true</skipITs>
5861
<alias-test-skipITs>true</alias-test-skipITs>
@@ -152,10 +155,6 @@
152155
<groupId>org.apache.maven.plugins</groupId>
153156
<artifactId>maven-surefire-plugin</artifactId>
154157
<version>3.0.0-M5</version>
155-
<configuration>
156-
<!-- Created by jacoco plugin (inherited configuration) -->
157-
<argLine>${surefireArgLine}</argLine>
158-
</configuration>
159158
</plugin>
160159
<plugin>
161160
<groupId>io.rhpatrick.mojo</groupId>
@@ -183,25 +182,17 @@
183182
<version>0.8.7</version>
184183
<executions>
185184
<execution>
186-
<id>pre-unit-test</id>
185+
<id>prepare-agent</id>
187186
<goals>
188187
<goal>prepare-agent</goal>
189188
</goals>
190-
<configuration>
191-
<destFile>${sonar.jacoco.reportPath}</destFile>
192-
<propertyName>surefireArgLine</propertyName>
193-
</configuration>
194189
</execution>
195190
<execution>
196-
<id>post-unit-test</id>
197-
<phase>site</phase>
191+
<id>report</id>
192+
<phase>post-integration-test</phase>
198193
<goals>
199194
<goal>report</goal>
200195
</goals>
201-
<configuration>
202-
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
203-
<dataFile>${sonar.jacoco.reportPath}</dataFile>
204-
</configuration>
205196
</execution>
206197
</executions>
207198
</plugin>

0 commit comments

Comments
 (0)