Hi there
I am evaluating SonarCloud for my organization but am having trouble using the short lived branches feature when running from Google Cloud Build.
I have been looking through a number of similar threads and trying many different things to resolve but so far just spent nearly two days trying and failing.
I have used short lived branches successfully when run directly from my developer machine, but when running from Google Cloud I can see the branch is created, but doesn’t show any results or the bugs I intentionally introduced, or have any of the linked source code available. Again, intentionally introducing bugs do get picked up on master and releases branch when run locally, as well as master when run from Google Cloud Build, but not release branches from Google Cloud Build.
My project is a simple POC to see if we can use SonarCloud for what we need. It’s a Spring Boot app built with Maven, and am using the sonar-maven-plugin v3.6.0.1398
I do know that Google Cloud Build does a shallow clone of a git repo, which I worked around by adding a build step to fetch --unshallow. Actually added another step to fetch master too, although unnecessary. This was highlighted as a common issue for what I’m experiencing on some other similar threads, but hasn’t solved the problem for me.
I have also added the GitHub app for SonarCloud, just FYI, although I know at this point it’s only relevant for PR’s.
Do you have any working examples somewhere for Google Cloud Build. The fact that I can get this to run from Jenkins and from my local machine implies it’s something specific to how Google Cloud Build is doing things, but it’s all docker based so should work. Any help would be appreciated!
My Google Cloud Build config looks like this (for features branches)
steps:
- id: UNSHALLOW_REPO_CLONE
name: gcr.io/cloud-builders/git
args: ['fetch', '--unshallow']
- id: FETCH_MASTER
name: gcr.io/cloud-builders/git
args: ['fetch', 'origin', 'master']
- id: TEST_SONAR
name: maven:3.6.0-jdk-8-slim
entrypoint: mvn
args:
- '--batch-mode'
- 'clean'
- 'test'
- 'sonar:sonar'
- '-Dsonar.branch.name=$BRANCH_NAME'
- '-Dsonar.branch.target=master'
The short lived branch results:
Branches page:
My sonar properties are set to(some additional set just trying to get things to work):
<sonar.login>${sonarLogin}</sonar.login>
<sonar.projectKey>${sonarProjectKey}</sonar.projectKey>
<sonar.organization>${sonarOrg}</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.scm.provider>git</sonar.scm.provider>
<sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
<sonar.java.binaries>target/classes</sonar.java.binaries>
<sonar.projectBaseDir>${project.basedir}</sonar.projectBaseDir>
<sonar.working.directory>.sonar</sonar.working.directory>
<sonar.sources>src/main</sonar.sources>
<sonar.tests>src/test</sonar.tests>
<sonar.verbose>true</sonar.verbose>
And my log output:
FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
From https://source.developers.google.com/p/sandbox-324324/r/github_Connected-Journeys_demo-app-spring-boot-docker
* branch 877c81f247a320c8e0dcae9b74be433458dfddfd -> FETCH_HEAD
HEAD is now at 877c81f Sonar6
BUILD
Starting Step #0 - "UNSHALLOW_REPO_CLONE"
Step #0 - "UNSHALLOW_REPO_CLONE": Already have image (with digest): gcr.io/cloud-builders/git
Step #0 - "UNSHALLOW_REPO_CLONE": From https://source.developers.google.com/p/sandbox-324324/r/github_Connected-Journeys_demo-app-spring-boot-docker
Step #0 - "UNSHALLOW_REPO_CLONE": * [new branch] feature/test6 -> origin/feature/test6
Step #0 - "UNSHALLOW_REPO_CLONE": * [new branch] master -> origin/master
Finished Step #0 - "UNSHALLOW_REPO_CLONE"
Starting Step #1 - "FETCH_MASTER"
Step #1 - "FETCH_MASTER": Already have image (with digest): gcr.io/cloud-builders/git
Step #1 - "FETCH_MASTER": From https://source.developers.google.com/p/sandbox-324324/r/github_Connected-Journeys_demo-app-spring-boot-docker
Step #1 - "FETCH_MASTER": * branch master -> FETCH_HEAD
Finished Step #1 - "FETCH_MASTER"
Starting Step #2 - "TEST_SONAR"
Step #2 - "TEST_SONAR": Pulling image: maven:3.6.0-jdk-8-slim
Step #2 - "TEST_SONAR": 3.6.0-jdk-8-slim: Pulling from library/maven
Step #2 - "TEST_SONAR": Status: Downloaded newer image for maven:3.6.0-jdk-8-slim
Step #2 - "TEST_SONAR": [INFO] -------------------------------------------------------
Step #2 - "TEST_SONAR": [INFO] T E S T S
Step #2 - "TEST_SONAR": [INFO] -------------------------------------------------------
Step #2 - "TEST_SONAR": [INFO] Running nz.co.connectedjourneys.sre.demo.ApiTest
Step #2 - "TEST_SONAR": 21:44:07.426 [main] INFO nz.co.connectedjourneys.sre.demo.Api - hit: null - counter: 0.0
Step #2 - "TEST_SONAR": [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.394 s - in nz.co.connectedjourneys.sre.demo.ApiTest
Step #2 - "TEST_SONAR": [INFO]
Step #2 - "TEST_SONAR": [INFO] Results:
Step #2 - "TEST_SONAR": [INFO]
Step #2 - "TEST_SONAR": [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
Step #2 - "TEST_SONAR": [INFO]
Step #2 - "TEST_SONAR": [INFO]
Step #2 - "TEST_SONAR": [INFO] --- sonar-maven-plugin:3.6.0.1398:sonar (default-cli) @ demo-app-spring-boot-docker ---
Step #2 - "TEST_SONAR": [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.pom
Step #2 - "TEST_SONAR": [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.pom (3.0 kB at 141 kB/s)
Step #2 - "TEST_SONAR": [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/sonarsource/scanner/api/sonar-scanner-api/2.12.0.1661/sonar-scanner-api-2.12.0.1661.pom
Step #2 - "TEST_SONAR": [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/sonarsource/scanner/api/sonar-scanner-api/2.12.0.1661/sonar-scanner-api-2.12.0.1661.pom (5.4 kB at 244 kB/s)
Step #2 - "TEST_SONAR": [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/sonarsource/scanner/api/sonar-scanner-api-parent/2.12.0.1661/sonar-scanner-api-parent-2.12.0.1661.pom
Step #2 - "TEST_SONAR": [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/sonarsource/scanner/api/sonar-scanner-api-parent/2.12.0.1661/sonar-scanner-api-parent-2.12.0.1661.pom (5.1 kB at 233 kB/s)
Step #2 - "TEST_SONAR": [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/sonarsource/parent/parent/48/parent-48.pom
Step #2 - "TEST_SONAR": [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/sonarsource/parent/parent/48/parent-48.pom (32 kB at 1.4 MB/s)
Step #2 - "TEST_SONAR": [INFO] Downloading from central: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.6/commons-lang-2.6.pom
Step #2 - "TEST_SONAR": [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.6/commons-lang-2.6.pom (17 kB at 700 kB/s)
Step #2 - "TEST_SONAR": [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-parent/17/commons-parent-17.pom
Step #2 - "TEST_SONAR": [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-parent/17/commons-parent-17.pom (31 kB at 1.2 MB/s)
Step #2 - "TEST_SONAR": [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
Step #2 - "TEST_SONAR": [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/sonarsource/scanner/api/sonar-scanner-api/2.12.0.1661/sonar-scanner-api-2.12.0.1661.jar
Step #2 - "TEST_SONAR": [INFO] Downloading from central: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
Step #2 - "TEST_SONAR": [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar (28 kB at 710 kB/s)
Step #2 - "TEST_SONAR": [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.6/commons-lang-2.6.jar (284 kB at 4.3 MB/s)
Step #2 - "TEST_SONAR": [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/sonarsource/scanner/api/sonar-scanner-api/2.12.0.1661/sonar-scanner-api-2.12.0.1661.jar (601 kB at 6.7 MB/s)
Step #2 - "TEST_SONAR": [INFO] User cache: /root/.sonar/cache
Step #2 - "TEST_SONAR": [INFO] SonarQube version: 7.7.0
Step #2 - "TEST_SONAR": [INFO] Default locale: "en", source code encoding: "UTF-8"
Step #2 - "TEST_SONAR": [INFO] Load global settings
Step #2 - "TEST_SONAR": [INFO] Load global settings (done) | time=900ms
Step #2 - "TEST_SONAR": [INFO] Server id: BD367519-AWHW8ct9-T_TB3XqouNu
Step #2 - "TEST_SONAR": [INFO] User cache: /root/.sonar/cache
Step #2 - "TEST_SONAR": [INFO] Load/download plugins
Step #2 - "TEST_SONAR": [INFO] Load plugins index
Step #2 - "TEST_SONAR": [INFO] Load plugins index (done) | time=249ms
Step #2 - "TEST_SONAR": [INFO] Load/download plugins (done) | time=30617ms
Step #2 - "TEST_SONAR": [INFO] Loaded core extensions: developer-scanner
Step #2 - "TEST_SONAR": [INFO] Process project properties
Step #2 - "TEST_SONAR": [INFO] Execute project builders
Step #2 - "TEST_SONAR": [INFO] Execute project builders (done) | time=18ms
Step #2 - "TEST_SONAR": [INFO] Project key: Connected-Journeys_demo-app-spring-boot-docker
Step #2 - "TEST_SONAR": [INFO] Base dir: /workspace
Step #2 - "TEST_SONAR": [INFO] Working dir: /workspace/.sonar
Step #2 - "TEST_SONAR": [INFO] Load project settings
Step #2 - "TEST_SONAR": [INFO] Load project settings (done) | time=174ms
Step #2 - "TEST_SONAR": [INFO] Load project branches
Step #2 - "TEST_SONAR": [INFO] Load project branches (done) | time=165ms
Step #2 - "TEST_SONAR": [INFO] Load project pull requests
Step #2 - "TEST_SONAR": [INFO] Load project pull requests (done) | time=157ms
Step #2 - "TEST_SONAR": [INFO] Load branch configuration
Step #2 - "TEST_SONAR": [INFO] Load branch configuration (done) | time=11ms
Step #2 - "TEST_SONAR": [INFO] Load project repositories
Step #2 - "TEST_SONAR": [INFO] Load project repositories (done) | time=277ms
Step #2 - "TEST_SONAR": [INFO] Load quality profiles
Step #2 - "TEST_SONAR": [INFO] Load quality profiles (done) | time=189ms
Step #2 - "TEST_SONAR": [INFO] Load active rules
Step #2 - "TEST_SONAR": [INFO] Load active rules (done) | time=4410ms
Step #2 - "TEST_SONAR": [INFO] Load metrics repository
Step #2 - "TEST_SONAR": [INFO] Load metrics repository (done) | time=174ms
Step #2 - "TEST_SONAR": [INFO] Organization key: connected-journeys
Step #2 - "TEST_SONAR": [INFO] Branch name: feature/test6, type: short living
Step #2 - "TEST_SONAR": [INFO] SCM collecting changed files in the branch
Step #2 - "TEST_SONAR": [INFO] SCM collecting changed files in the branch (done) | time=193ms
Step #2 - "TEST_SONAR": [INFO] Indexing files...
Step #2 - "TEST_SONAR": [INFO] Project configuration:
Step #2 - "TEST_SONAR": [INFO] 12 files indexed
Step #2 - "TEST_SONAR": [INFO] Quality profile for java: Sonar way
Step #2 - "TEST_SONAR": [INFO] ------------- Run sensors on module demo-app-spring-boot-docker
Step #2 - "TEST_SONAR": [INFO] Sensor JavaSquidSensor [java]
Step #2 - "TEST_SONAR": [INFO] Configured Java source version (sonar.java.source): 8
Step #2 - "TEST_SONAR": [INFO] JavaClasspath initialization
Step #2 - "TEST_SONAR": [INFO] JavaClasspath initialization (done) | time=21ms
Step #2 - "TEST_SONAR": [INFO] JavaTestClasspath initialization
Step #2 - "TEST_SONAR": [INFO] JavaTestClasspath initialization (done) | time=7ms
Step #2 - "TEST_SONAR": [INFO] Java Main Files AST scan
Step #2 - "TEST_SONAR": [INFO] 7 source files to be analyzed
Step #2 - "TEST_SONAR": [INFO] 7/7 source files have been analyzed
Step #2 - "TEST_SONAR": [INFO] Java Main Files AST scan (done) | time=2144ms
Step #2 - "TEST_SONAR": [INFO] Java Test Files AST scan
Step #2 - "TEST_SONAR": [INFO] 1 source files to be analyzed
Step #2 - "TEST_SONAR": [INFO] 1/1 source files have been analyzed
Step #2 - "TEST_SONAR": [INFO] Java Test Files AST scan (done) | time=72ms
Step #2 - "TEST_SONAR": [INFO] Sensor JavaSquidSensor [java] (done) | time=3288ms
Step #2 - "TEST_SONAR": [INFO] Sensor SurefireSensor [java]
Step #2 - "TEST_SONAR": [INFO] parsing [/workspace/target/surefire-reports]
Step #2 - "TEST_SONAR": [INFO] Sensor SurefireSensor [java] (done) | time=64ms
Step #2 - "TEST_SONAR": [INFO] Sensor JaCoCoSensor [java]
Step #2 - "TEST_SONAR": [INFO] Sensor JaCoCoSensor [java] (done) | time=1ms
Step #2 - "TEST_SONAR": [INFO] Sensor JavaXmlSensor [java]
Step #2 - "TEST_SONAR": [INFO] Sensor JavaXmlSensor [java] (done) | time=1ms
Step #2 - "TEST_SONAR": [INFO] Sensor HTML [web]
Step #2 - "TEST_SONAR": [INFO] Sensor HTML [web] (done) | time=24ms
Step #2 - "TEST_SONAR": [INFO] Sensor JaCoCo XML Report Importer [jacoco]
Step #2 - "TEST_SONAR": [INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=7ms
Step #2 - "TEST_SONAR": [INFO] Sensor Zero Coverage Sensor
Step #2 - "TEST_SONAR": [INFO] Sensor Zero Coverage Sensor (done) | time=32ms
Step #2 - "TEST_SONAR": [INFO] Sensor JavaSecuritySensor [security]
Step #2 - "TEST_SONAR": [INFO] Reading UCFGs from: /workspace/.sonar/ucfg2/java
Step #2 - "TEST_SONAR": [INFO] 21:45:06.623 Building Type propagation graph
Step #2 - "TEST_SONAR": [INFO] 21:45:06.642 Running Tarjan on 30 nodes
Step #2 - "TEST_SONAR": [INFO] 21:45:06.648 Tarjan found 30 components
Step #2 - "TEST_SONAR": [INFO] 21:45:06.653 Variable type analysis: done
Step #2 - "TEST_SONAR": [INFO] UCFGs: 13, excluded: 13, source entrypoints: 0
Step #2 - "TEST_SONAR": [INFO] No UCFGs have been included for analysis.
Step #2 - "TEST_SONAR": [INFO] Sensor JavaSecuritySensor [security] (done) | time=155ms
Step #2 - "TEST_SONAR": [INFO] Sensor CSharpSecuritySensor [security]
Step #2 - "TEST_SONAR": [INFO] Reading UCFGs from: /workspace/ucfg_cs2
Step #2 - "TEST_SONAR": [INFO] 21:45:06.676 Building Type propagation graph
Step #2 - "TEST_SONAR": [INFO] 21:45:06.676 Running Tarjan on 0 nodes
Step #2 - "TEST_SONAR": [INFO] 21:45:06.676 Tarjan found 0 components
Step #2 - "TEST_SONAR": [INFO] 21:45:06.676 Variable type analysis: done
Step #2 - "TEST_SONAR": [INFO] UCFGs: 0, excluded: 0, source entrypoints: 0
Step #2 - "TEST_SONAR": [INFO] No UCFGs have been included for analysis.
Step #2 - "TEST_SONAR": [INFO] Sensor CSharpSecuritySensor [security] (done) | time=2ms
Step #2 - "TEST_SONAR": [INFO] ------------- Run sensors on project
Step #2 - "TEST_SONAR": [INFO] Sensor Java CPD Block Indexer
Step #2 - "TEST_SONAR": [INFO] Sensor Java CPD Block Indexer (done) | time=48ms
Step #2 - "TEST_SONAR": [INFO] 4 files had no CPD blocks
Step #2 - "TEST_SONAR": [INFO] Calculating CPD for 3 files
Step #2 - "TEST_SONAR": [INFO] CPD calculation finished
Step #2 - "TEST_SONAR": [INFO] SCM writing changed lines
Step #2 - "TEST_SONAR": [INFO] SCM writing changed lines (done) | time=9ms
Step #2 - "TEST_SONAR": [INFO] Analysis report generated in 279ms, dir size=127 KB
Step #2 - "TEST_SONAR": [INFO] Analysis report compressed in 36ms, zip size=30 KB
Step #2 - "TEST_SONAR": [INFO] Analysis report generated in /workspace/.sonar/scanner-report
Step #2 - "TEST_SONAR": [INFO] Analysis report uploaded in 982ms
Step #2 - "TEST_SONAR": [INFO] ANALYSIS SUCCESSFUL, you can browse https://sonarcloud.io/dashboard?id=Connected-Journeys_demo-app-spring-boot-docker&branch=feature%2Ftest6&resolved=false
Step #2 - "TEST_SONAR": [INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
Step #2 - "TEST_SONAR": [INFO] More about the report processing at https://sonarcloud.io/api/ce/task?id=AWjo0hKjuDWrs3eUlgZz
Step #2 - "TEST_SONAR": [INFO] Analysis total time: 18.186 s
Step #2 - "TEST_SONAR": [INFO] ------------------------------------------------------------------------
Step #2 - "TEST_SONAR": [INFO] BUILD SUCCESS
Step #2 - "TEST_SONAR": [INFO] ------------------------------------------------------------------------
Step #2 - "TEST_SONAR": [INFO] Total time: 02:31 min
Step #2 - "TEST_SONAR": [INFO] Finished at: 2019-02-13T21:45:08Z
Step #2 - "TEST_SONAR": [INFO] ------------------------------------------------------------------------
Finished Step #2 - "TEST_SONAR"
PUSH
DONE