Skip to content

Commit

Permalink
ES-1657/enable sonar cloud (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbrereton authored Apr 18, 2024
1 parent 1c8f072 commit c7e7374
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .ci/JenkinsfileSonarCloud
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@Library('[email protected]') _

import com.r3.build.agents.KubernetesAgent
import com.r3.build.enums.BuildEnvironment
import com.r3.build.enums.KubernetesCluster
import com.r3.build.BuildConstants
import com.r3.build.utils.GitUtils
import com.r3.build.utils.SnykUtils

KubernetesAgent k8s = new KubernetesAgent(
BuildEnvironment.AMD64_LINUX_JAVA17,
KubernetesCluster.JenkinsAgents,
1
)

GitUtils gitUtils = new GitUtils(this)
SnykUtils snykUtils = new SnykUtils(this)

pipeline {
agent {
kubernetes {
cloud k8s.buildCluster.cloudName
yaml k8s.JSON
yamlMergeStrategy merge() // important to keep tolerations from the inherited template
idleMinutes 15
podRetention always()
nodeSelector k8s.nodeSelector
label k8s.jenkinsLabel
showRawYaml true
defaultContainer k8s.defaultContainer.name
}
}

environment {
ARTIFACTORY_CREDENTIALS = credentials('artifactory-credentials')
CORDA_ARTIFACTORY_PASSWORD = "${env.ARTIFACTORY_CREDENTIALS_PSW}"
CORDA_ARTIFACTORY_USERNAME = "${env.ARTIFACTORY_CREDENTIALS_USR}"
BUILD_CACHE_CREDENTIALS = credentials('gradle-ent-cache-credentials')
BUILD_CACHE_PASSWORD = "${env.BUILD_CACHE_CREDENTIALS_PSW}"
BUILD_CACHE_USERNAME = "${env.BUILD_CACHE_CREDENTIALS_USR}"
CORDA_GRADLE_SCAN_KEY = credentials('gradle-build-scans-key')
GRADLE_USER_HOME = "/host_tmp/gradle"
SNYK_TOKEN = credentials("r3-snyk-corda5")
SNYK_ORG_ID = credentials("corda5-snyk-org-id")
}

options {
timestamps()
}

triggers {
cron (gitUtils.isReleaseBranch() ? '@midnight' : '')
}

stages {
stage('SonarQube analysis') {
when {
expression { return env.BRANCH_NAME == gitUtils.getDefaultBranch(gitUtils.getRepoName())}
}
steps {
withSonarQubeEnv('SonarCloud') {
sh './gradlew sonar -Si'
}
}
}
stage('Snyk Code analysis') {
steps {
script {
snykUtils.runSnykCode()
}
}
}
}
}
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
id 'io.snyk.gradle.plugin.snykplugin'
id 'com.github.ben-manes.versions' // discover possible dependency version upgrades
id 'org.cyclonedx.bom' apply false
id "org.sonarqube"
}

snyk {
Expand All @@ -22,6 +23,14 @@ snyk {
autoUpdate = true
}

sonar {
properties {
property "sonar.projectKey", "corda"
property "sonar.organization", "corda"
property "sonar.host.url", "https://sonarcloud.io"
}
}

ext.pluginsDir = "$buildDir/plugins"

if (System.getenv("RELEASE_VERSION")?.trim()) {
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ licenseUrl = http://www.apache.org/licenses/LICENSE-2.0.txt

# Cyclonedx Bom generation version
cyclonedxVersion = 1.7.4

# Sonar verison
sonarVersion = 5.0.0.4638
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pluginManagement {
id 'io.snyk.gradle.plugin.snykplugin' version snykVersion
id 'com.github.ben-manes.versions' version dependencyCheckVersion
id "org.cyclonedx.bom" version cyclonedxVersion
id "org.sonarqube" version sonarVersion
}
}

Expand Down

0 comments on commit c7e7374

Please sign in to comment.