Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES-1657/Add sonar cloud scan #1608

Merged
merged 20 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .ci/JenkinsfileSonarCloud
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@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') {
steps {
withSonarQubeEnv('SonarCloud') {
sh './gradlew sonar -Si'
}
}
}
stage('Snyk Code analysis') {
steps {
script {
snykUtils.runSnykCode()
}
}
}
}
}
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ plugins {
alias libs.plugins.dokka
alias libs.plugins.dependency.check.versions // discover possible dependency version upgrades
alias libs.plugins.cyclonedx.bom apply false
id "org.sonarqube" version "4.4.1.3373"
}

snyk {
Expand All @@ -35,6 +36,14 @@ snyk {
autoUpdate = true
}

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

def revision = {
if (System.getenv("CORDA_REVISION")) {
return System.getenv("CORDA_REVISION")
Expand Down Expand Up @@ -113,6 +122,7 @@ subprojects {
group 'net.corda'

pluginManager.withPlugin('java') {
apply plugin: 'org.sonarqube'
java {
toolchain {
languageVersion = of(javaVersion.majorVersion.toInteger())
Expand Down