Skip to content

Commit

Permalink
BFD-2876: Upload Test Results to SonarQube (#1953)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael J Burling <[email protected]>
  • Loading branch information
aadedejifearless and mjburling authored Sep 25, 2023
1 parent c6a267e commit dcf10f0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
9 changes: 7 additions & 2 deletions apps/build.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ class AppBuildResults implements Serializable {
* Builds the Java applications and utilities in this directory: Data Pipeline, Data Server, etc.
*
* @param verboseMaven when `false`, maven runs with `--quiet` and `--batch-mode` flags
* @param runTests when `true`, runs unit and integration tests, default is `false`
* @return An {@link AppBuildResults} instance containing the paths to the artifacts that were built.
* @throws Exception An exception will be bubbled up if the Maven build fails.
*/
def build(boolean verboseMaven) {
def build(boolean verboseMaven, boolean runTests = false) {
withCredentials([string(credentialsId: 'bfd-aws-account-id', variable: 'ACCOUNT_ID')]) {
// Set the auth token for aws code artifact
env.CODEARTIFACT_AUTH_TOKEN = sh(
Expand Down Expand Up @@ -85,7 +86,11 @@ EOF

dir ('apps') {
quietFlags = verboseMaven ? '' : '--quiet --batch-mode'
sh "mvn ${quietFlags} --threads 1C --update-snapshots -DskipITs -DskipTests -Dmaven.javadoc.skip=true -Dmaven.build.cache.enabled=false clean verify"
if (runTests) {
sh "mvn ${quietFlags} --threads 1C -Dmaven.javadoc.skip=true -Dcheckstyle.skip -Dmaven.build.cache.enabled=false -Dmaven.jacoco.skip=false clean install"
} else {
sh "mvn ${quietFlags} --threads 1C --update-snapshots -DskipITs -DskipTests -Dmaven.javadoc.skip=true -Dmaven.build.cache.enabled=false clean verify"
}
}

return new AppBuildResults(
Expand Down
4 changes: 2 additions & 2 deletions apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
<maven.jacoco.skip>true</maven.jacoco.skip>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.build.directory}/coverage-reports/jacoco-ut.exec</sonar.jacoco.reportPath>
<sonar.jacoco.itReportPath>${project.build.directory}/coverage-reports/jacoco-it.exec</sonar.jacoco.itReportPath>
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/coverage-reports/jacoco-ut/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.coverage.jacoco.itReportPath>${project.build.directory}/coverage-reports/jacoco-it/jacoco.xml</sonar.coverage.jacoco.itReportPath>
<micrometer.version>1.11.2</micrometer.version>
<metrics.version>4.2.19</metrics.version>
<dropwizard-metrics-newrelic.version>0.9.0</dropwizard-metrics-newrelic.version>
Expand Down
56 changes: 43 additions & 13 deletions ops/jenkins/bfd-jenkins-sonarqube/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env groovy

// These variables are accessible throughout this file (except inside methods and classes).
def verboseMaven = params.verbose_mvn_logging
def appBuildResults
def verboseMaven
if (params.verbose_mvn_logging != null) {
verboseMaven = params.verbose_mvn_logging
} else {
verboseMaven = false
}

pipeline {
agent {
Expand All @@ -13,28 +17,48 @@ apiVersion: v1
kind: Pod
spec:
serviceAccount: bfd
volumes:
- name: docker-socket
emptyDir: {}
containers:
- name: docker-daemon
image: docker:20.10-dind
securityContext:
privileged: true
volumeMounts:
- name: docker-socket
mountPath: /var/run
resources:
requests:
memory: '8192Mi'
cpu: '4000m'
limits:
memory: '8192Mi'
cpu: '4000m'
- name: bfd-cbc-build
image: 'public.ecr.aws/c2o1d8s9/bfd-cbc-build:jdk17-mvn3-tfenv3-latest'
volumeMounts:
- name: docker-socket
mountPath: /var/run
command:
- cat
tty: true
imagePullPolicy: Always
resources:
requests:
memory: '16384Mi'
cpu: '8000m'
memory: '8192Mi'
cpu: '4000m'
limits:
memory: '16384Mi'
cpu: '8000m'
memory: '8192Mi'
cpu: '4000m'
"""
}
}
parameters {
booleanParam(name: 'verbose_mvn_logging',
description: 'When true, `mvn` will produce verbose logs.',
defaultValue: false)
}
}
environment {
SONAR_TOKEN = credentials('svc-sonar-bfd')
SONAR_PROJECT_KEY = 'bfd-parent'
Expand All @@ -50,18 +74,24 @@ spec:
//Authentication of AWS to run Build.groovy
awsAuth.assumeRole()
// Perform Build steps
appBuildResults = scriptForApps.build(verboseMaven)
scriptForApps.build(verboseMaven, true)
}
}
}
stage ('SonarQube Analysis') {
steps {
script {
sh "mvn -f apps/ sonar:sonar" +
" -Dsonar.projectKey=${SONAR_PROJECT_KEY}" +
" -Dsonar.host.url=${SONAR_HOST_URL}" +
" -Dsonar.login=${SONAR_TOKEN}" +
" -Dmaven.build.cache.enabled=false"
dir ('apps') {
sh "mvn sonar:sonar" +
" -Dsonar.projectKey=${SONAR_PROJECT_KEY}" +
" -Dsonar.host.url=${SONAR_HOST_URL}" +
" -Dsonar.login=${SONAR_TOKEN}" +
" -Dmaven.build.cache.enabled=false" +
" -DskipITs" +
" -DskipTests" +
" -Dsonar.exclusions='*.java'" +
" -Dsonar.coverage.jacoco.xmlReportPaths=target/coverage-reports/jacoco-it/jacoco.xml,target/coverage-reports/jacoco-ut/jacoco.xml"
}
}
}
}
Expand Down

0 comments on commit dcf10f0

Please sign in to comment.