Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Travis CI SonarCloud error "Project was never analyzed. A regular analysis is required before a branch analysis"

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.

like image 812
Meena Chaudhary Avatar asked May 19 '19 17:05

Meena Chaudhary


People also ask

What happens during analysis of SonarQube?

What happens during analysis? During analysis, data is requested from the server, the files provided to the analysis are analyzed, and the resulting data is sent back to the server at the end in the form of a report, which is then analyzed asynchronously server-side.

Is a regular analysis required before a branch analysis?

A regular analysis is required before a branch analysis" - Stack Overflow Travis CI SonarCloud error "Project was never analyzed. A regular analysis is required before a branch analysis"

What to do if Travis CI with sonarcloud is not authorized?

Error using Travis CI with Sonarcloud: Not authorized. Please check the properties sonar.login and sonar.password I'm following Get started instructions on sonarcloud.io to execute the SonarQube Scanner for Maven from my computer:

Why am I getting project was never analyzed?

You are trying to directly analyze a branch whereas your project has not been created yet. This is why you get the following message: Project was never analyzed. A regular analysis is required before a branch analysis This should fix your issue. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.

How to analyze all branches of a Travis project?

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.


2 Answers

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.
like image 75
sshepel Avatar answered Oct 18 '22 10:10

sshepel


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
like image 24
agabrys Avatar answered Oct 18 '22 10:10

agabrys