8

Hi I am automating code coverage on SonarCloud using Travis CI for a Maven application.

Now, running the sonar:sonar command locally submits the report on SoundCloud and I can see it as shown below with Branch master

enter image description here

Now I have also configured .travis.yml file to auto push the report to SoundCloud on each build as below

enter image description here

But when build is triggered by Travis CI it fails with following error

[INFO] Load project branches
[INFO] Load project branches (done) | time=114ms
[INFO] Load project pull requests
[INFO] Load project pull requests (done) | time=116ms
[INFO] Load branch configuration
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.884 s
[INFO] Finished at: 2019-05-19T16:47:23Z
[INFO] Final Memory: 93M/496M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project safenest-java-server: 

 Project was never analyzed. A regular analysis is required before a branch analysis`

I am new to SonarCloud and couldn't find much documentation to get help with this. Can somebody explain what exactly A regular analysis is required mean? And how to fix this?

Thanks in advance.

Meena Chaudhary
  • 9,909
  • 16
  • 60
  • 94

2 Answers2

3

You should check following parameters:

  1. Project key generated during maven build and generated on SonarCloud (or make sure that you set sonar.projectKey property that was generated on SonarCloud).
  2. Check if provided Token value matching the one on SonarCloud (you can provide your own value on project setup page.
sshepel
  • 880
  • 1
  • 9
  • 16
1

The error message means:

Please analyze main branch, before you will analyze other branches

You have to build main repository branch (usually master) with this configuration on Travis. After that you should be able to analyze all other branches. I hit the same problem when I was trying to analyze a feature branch which integrates my project with SonarCloud for the first time. I just merged my feature to master, pushed, and my project has been analyzed successfully. My configuration is similar to yours:

language: java
jdk: openjdk8
env: MVN_VERSION='3.6.0'
addons:
  sonarcloud:
    organization: $SONAR_ORGANIZATION
    token:
      secure: $SONAR_TOKEN
before_install:
  - wget https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/$MVN_VERSION/apache-maven-$MVN_VERSION-bin.zip
  - unzip -qq apache-maven-$MVN_VERSION-bin.zip
  - export M2_HOME=$PWD/apache-maven-$MVN_VERSION
  - export PATH=$M2_HOME/bin:$PATH
script:
  - mvn -B -e verify site
  - if [ -n "$SONAR_TOKEN" ]; then
      mvn -B -e sonar:sonar -Dsonar.sources=pom.xml,src/main;
    fi
agabrys
  • 8,728
  • 3
  • 35
  • 73