This is an automated email from the ASF dual-hosted git repository. zabetak pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hive.git
commit 4cafe1f8b319498a4dcc9705e25afd9a5d73e9bd Author: Alessandro Solimando <[email protected]> AuthorDate: Thu Apr 28 12:20:06 2022 +0200 HIVE-26196: Integrate Sonar analysis for master branch and PRs (Alessandro Solimando, reviewed by Stamatis Zampetakis, Zoltan Haindrich) Closes #3254 --- Jenkinsfile | 40 ++++++++++++++++++++++++++++++++++++++++ pom.xml | 2 ++ 2 files changed, 42 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 09b6cd377d8..fab48ede662 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -103,6 +103,21 @@ df -h } } +def sonarAnalysis(args) { + withCredentials([string(credentialsId: 'sonar', variable: 'SONAR_TOKEN')]) { + def mvnCmd = """mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar \ + -Dsonar.organization=apache \ + -Dsonar.projectKey=apache_hive \ + -Dsonar.host.url=https://sonarcloud.io \ + """+args+" -DskipTests -Dit.skipTests -Dmaven.javadoc.skip" + + sh """#!/bin/bash -e + sw java 11 && . /etc/profile.d/java.sh + export MAVEN_OPTS=-Xmx5G + """+mvnCmd + } +} + def hdbPodTemplate(closure) { podTemplate( containers: [ @@ -304,6 +319,31 @@ tar -xzf packaging/target/apache-hive-*-nightly-*-src.tar.gz } } } + branches['sonar'] = { + executorNode { + if(env.CHANGE_BRANCH == 'master') { + stage('Prepare') { + loadWS(); + } + stage('Sonar') { + sonarAnalysis("-Dsonar.branch.name=${CHANGE_BRANCH}") + } + } else if(env.CHANGE_ID) { + stage('Prepare') { + loadWS(); + } + stage('Sonar') { + sonarAnalysis("""-Dsonar.pullrequest.github.repository=apache/hive \ + -Dsonar.pullrequest.key=${CHANGE_ID} \ + -Dsonar.pullrequest.branch=${CHANGE_BRANCH} \ + -Dsonar.pullrequest.base=${CHANGE_TARGET} \ + -Dsonar.pullrequest.provider=GitHub""") + } + } else { + echo "Skipping sonar analysis, we only run it on PRs and on the master branch" + } + } + } for (int i = 0; i < splits.size(); i++) { def num = i def split = splits[num] diff --git a/pom.xml b/pom.xml index 7d6c56994e7..325856ada73 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,8 @@ <hive.path.to.root>.</hive.path.to.root> <hive.jdbc.driver.classifier>standalone</hive.jdbc.driver.classifier> <checkstyle.conf.dir>${basedir}/${hive.path.to.root}/checkstyle</checkstyle.conf.dir> + <!-- SonarCloud-related variables --> + <sonar.moduleKey>${project.groupId}:${project.artifactId}</sonar.moduleKey> <!-- Test Properties --> <test.extra.path/> <!--suppress UnresolvedMavenProperty -->
