Sonarqube: line out of range since file shrinks after merge with master

孤街浪徒 提交于 2020-06-01 06:18:42

问题


There is a fileA on master (say it consists of 1000 lines)

We are on feature_branch, where fileA has length of say 1050 lines.

On our CI pipeline, we are running coverage (it is a Python project) and it produces coverage.xml, to be used as cov input to SQ.

Our SQ preview stage is as follows:

    - git config --global user.name "SonarQube"
    - git config --global user.email "sonarqube@somedomain.com"
    - git checkout origin/master
    - git merge $CI_BUILD_REF --no-commit --no-ff
    - sonar-scanner -Dsonar.analysis.mode=preview -Dsonar.gitlab.project_id=$CI_PROJECT_PATH -Dsonar.login=$SONARQUBE_TOKEN -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
  except:
   - master@mainprojectnamespace

The problem is the following:

AFTER the merge, fileA ends up having (again) 1000 lines

HOWEVER, coverage was run BEFORE the merge (in a previous job) so it includes results for lines > 1000 (which is fileA's length after the merge)

This causes (I believe) the following error:

ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Line 1040 is out of range in the file path/to/fileA.py (lines: 1000)

How do we go about this?


回答1:


SonarPython, like all code analyzers that import coverage report, requires that analyzed source code is strictly identical to the one used to generate the coverage report. First, you should challenge the need to merge your branch before running sonar-scanner. And, if you really need to run sonar-scanner on a branch merged with master, you also need to run the coverage analysis on the same branch merged with master.



来源:https://stackoverflow.com/questions/50461872/sonarqube-line-out-of-range-since-file-shrinks-after-merge-with-master

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!