gabrie-allaigre / sonar-gitlab-plugin

Add to each commit GitLab in a global commentary on the new anomalies added by this commit and add comment lines of modified files
GNU Lesser General Public License v3.0
713 stars 207 forks source link

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

Open manasatest opened 5 years ago

manasatest commented 5 years ago

$ ./gradlew sonarqube -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.branch.name=$CI_COMMIT_REF_NAME

FAILURE: Build failed with an exception.

Running analysis using -Dsonar.branch.name=$CI_COMMIT_REF_NAME on gitlab always fails for branch/master. How to fix this issue for all the branches? Does sonar need always master analysis to be run first to create the project on sonar dashboard?

I'm using Sonarqube 7.5 EE.

gabrie-allaigre commented 5 years ago

Hi, Not use plugin with master, use only for others branches (feature branch) Branch plugin compare with master, if not master, error. Start analyze without use plugin

manasatest commented 5 years ago

Hi, You meant not to use the branch plugin for master?

gabrie-allaigre commented 5 years ago

For master, not use -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME

manasatest commented 5 years ago

Is there a reason why we don't use it? This is how its working for me.

This step runs the sonar analysis to preview the comments on GitLab

sonarqube_preview: stage: analysis variables: SONAR_ANALYSIS_MODE: preview dependencies:

This step runs the sonar analysis for master only

sonarqube-reports-master: stage: analysis variables: SONAR_ANALYSIS_MODE: publish dependencies:

This step runs the sonar analysis for branches only

sonarqube-reports-branch: stage: analysis variables: SONAR_ANALYSIS_MODE: publish dependencies:

cristemm commented 5 years ago

Hi, I keep getting this error:

ERROR: Error during SonarQube Scanner execution ERROR: Project was never analyzed. A regular analysis is required before a branch analysis ERROR: The SonarQube Scanner did not complete successfully 07:25:09.62 Creating a summary markdown file... 07:25:09.621 Post-processing failed. Exit code: 1 The command '/bin/sh -c dotnet /sonar-scanner/SonarScanner.MSBuild.dll end /d:sonar.login=

???

asakkour commented 4 years ago

I have same error in gitlab ci you do not have to specify the branch name in your script remove sonar.branch.name="$CI_COMMIT_REF_NAME" from your script

mcpierce commented 4 years ago

I'm getting this same error. We're trying to use SonarCloud to analyse our project on Github.

My action is:

name: "Analyze code with SonarCloud"

on:
  push:
    branches:
      - develop
      - enable-sonarcloud-java

jobs:
  sonarCloudTrigger:
    name: SonarCloud Trigger
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@master
      - name: Setup build environment
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: Build
        run: mvn sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Pci
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

(enable-sonarcloud-java is the testing branch I'm using)

The build runs and fails with the following error message:

2019-11-27T14:03:05.1655383Z Downloaded from central: https://repo.maven.apache.org/maven2/org/sonarsource/scanner/api/sonar-scanner-api/2.14.0.2002/sonar-scanner-api-2.14.0.2002.jar (625 kB at 6.8 MB/s)
2019-11-27T14:03:05.2652037Z [INFO] User cache: /home/runner/.sonar/cache
2019-11-27T14:03:07.2427672Z [INFO] SonarQube version: 8.0.0
2019-11-27T14:03:07.2898672Z [INFO] Default locale: "en", source code encoding: "UTF-8"
2019-11-27T14:03:07.5670037Z [INFO] Load global settings
2019-11-27T14:03:08.1794379Z [INFO] Load global settings (done) | time=613ms
2019-11-27T14:03:08.1860889Z [INFO] Server id: 74E9293D-AWHW8ct9-T_TB3XqouNu
2019-11-27T14:03:08.1911578Z [INFO] User cache: /home/runner/.sonar/cache
2019-11-27T14:03:08.1936476Z [INFO] Load/download plugins
2019-11-27T14:03:08.1938162Z [INFO] Load plugins index
2019-11-27T14:03:08.3655147Z [INFO] Load plugins index (done) | time=170ms
2019-11-27T14:03:30.3990797Z [INFO] Load/download plugins (done) | time=22205ms
2019-11-27T14:03:30.6718708Z [INFO] Loaded core extensions: developer-scanner
2019-11-27T14:03:31.5526487Z [INFO] Process project properties
2019-11-27T14:03:31.5695993Z [INFO] Execute project builders
2019-11-27T14:03:31.5741613Z [INFO] Execute project builders (done) | time=4ms
2019-11-27T14:03:31.5779050Z [INFO] Project key: org.comixed:comixed
2019-11-27T14:03:31.5779358Z [INFO] Base dir: /home/runner/work/comixed/comixed
2019-11-27T14:03:31.5779754Z [INFO] Working dir: /home/runner/work/comixed/comixed/target/sonar
2019-11-27T14:03:31.5860535Z [INFO] Load project settings for component key: 'org.comixed:comixed'
2019-11-27T14:03:31.7549088Z [INFO] Found an active CI vendor: 'Github Actions'
2019-11-27T14:03:31.7577306Z [INFO] Load project branches
2019-11-27T14:03:31.8514915Z [INFO] Load project branches (done) | time=96ms
2019-11-27T14:03:31.8545741Z [INFO] Load project pull requests
2019-11-27T14:03:31.9509226Z [INFO] Load project pull requests (done) | time=96ms
2019-11-27T14:03:31.9530111Z [INFO] Load branch configuration
2019-11-27T14:03:31.9545240Z [INFO] Github event: push
2019-11-27T14:03:32.1408893Z [INFO] Auto-configuring branch enable-sonarcloud-java
2019-11-27T14:03:32.1486127Z [INFO] ------------------------------------------------------------------------
2019-11-27T14:03:32.1487462Z [INFO] Reactor Summary:
2019-11-27T14:03:32.1488406Z [INFO] 
2019-11-27T14:03:32.1492233Z [INFO] comixed-parent 0.5.0-PRERELEASE .................... FAILURE [ 33.398 s]
2019-11-27T14:03:32.1494964Z [INFO] comixed-library 0.5.0-PRERELEASE ................... SKIPPED
2019-11-27T14:03:32.1497212Z [INFO] comixed-tasks 0.5.0-PRERELEASE ..................... SKIPPED
2019-11-27T14:03:32.1499174Z [INFO] comixed-services 0.5.0-PRERELEASE .................. SKIPPED
2019-11-27T14:03:32.1501226Z [INFO] comixed-rest-api 0.5.0-PRERELEASE .................. SKIPPED
2019-11-27T14:03:32.1503873Z [INFO] comixed-frontend 0.5.0-PRERELEASE .................. SKIPPED
2019-11-27T14:03:32.1506044Z [INFO] comixed-app 0.5.0-PRERELEASE ....................... SKIPPED
2019-11-27T14:03:32.1508623Z [INFO] comixed-importer 0.3.9-SNAPSHOT .................... SKIPPED
2019-11-27T14:03:32.1510623Z [INFO] ------------------------------------------------------------------------
2019-11-27T14:03:32.1511756Z [INFO] BUILD FAILURE
2019-11-27T14:03:32.1515311Z [INFO] ------------------------------------------------------------------------
2019-11-27T14:03:32.1517045Z [INFO] Total time:  40.480 s
2019-11-27T14:03:32.1520575Z [INFO] Finished at: 2019-11-27T14:03:32Z
2019-11-27T14:03:32.1524349Z [INFO] ------------------------------------------------------------------------
2019-11-27T14:03:32.1536110Z [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project comixed: Project was never analyzed. A regular analysis is required before a branch analysis. -> [Help 1]
rediphone commented 3 years ago

I have the same erro from an ADO run using sonaqube ERROR: Error during SonarScanner execution

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

this is the firstime this repo is being scanned in sonaqube

jKlaus-KI commented 3 years ago

@rediphone - did you get anywhere with this?