SonarQube“主分支没有代码行。” Jenkins说分析成功的问题

问题描述 投票:0回答:1

我有一个Maven项目,我想在Jenkins中进行构建和扫描。它使用SonarQube扫描仪扫描代码,并将结果上传到我的SonarQube服务器。詹金斯说一切都成功了,但是当我看看SonarQube时,我看到了...

enter image description here

Jenkins中的控制台输出看起来像这样:(注意:我只粘贴了最后一部分,而不是整个输出)

[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[JENKINS] Recording test results
[INFO] 
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ authentication-service ---
[INFO] Building jar: /var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/target/authentication-service-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.2.4.RELEASE:repackage (repackage) @ authentication-service ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ authentication-service ---
[INFO] Installing /var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/target/authentication-service-0.0.1-SNAPSHOT.jar to /var/jenkins_home/.m2/repository/com/authentication/microservice/authentication-service/0.0.1-SNAPSHOT/authentication-service-0.0.1-SNAPSHOT.jar
[INFO] Installing /var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/pom.xml to /var/jenkins_home/.m2/repository/com/authentication/microservice/authentication-service/0.0.1-SNAPSHOT/authentication-service-0.0.1-SNAPSHOT.pom
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ authentication-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ authentication-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 14 source files to /var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/target/classes
[INFO] /var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/src/main/java/com/authentication/microservice/authenticationservice/helpers/JsonWebTokenGenerator.java: /var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/src/main/java/com/authentication/microservice/authenticationservice/helpers/JsonWebTokenGenerator.java uses or overrides a deprecated API.
[INFO] /var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/src/main/java/com/authentication/microservice/authenticationservice/helpers/JsonWebTokenGenerator.java: Recompile with -Xlint:deprecation for details.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:00 min
[INFO] Finished at: 2020-05-22T18:41:07Z
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/pom.xml to com.authentication.microservice/authentication-service/0.0.1-SNAPSHOT/authentication-service-0.0.1-SNAPSHOT.pom
channel stopped
[AuthenticationService] $ /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner/bin/sonar-scanner -Dsonar.host.url=http://35.195.88.51 ******** -Dsonar.projectName=AuthenticationService -Dsonar.projectVersion=1.0 -Dsonar.projectKey=com.authentication.microservice:authentication-service -Dsonar.sources=/var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/target -Dsonar.projectBaseDir=/var/jenkins_home/workspace/AuthenticationService
INFO: Scanner configuration file: /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.3.0.2102
INFO: Java 1.8.0_221 Oracle Corporation (64-bit)
INFO: Linux 4.14.138+ amd64
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Scanner configuration file: /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 7.9.1
INFO: Default locale: "en_US", source code encoding: "US-ASCII" (analysis is platform dependent)
WARN: SonarScanner will require Java 11+ to run starting in SonarQube 8.x
INFO: Load global settings
INFO: Load global settings (done) | time=97ms
INFO: Server id: A7EE8CF2-AXI9JaBwRGaHU4KxYo1w
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=58ms
INFO: Load/download plugins (done) | time=117ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=11ms
INFO: Project key: com.authentication.microservice:authentication-service
INFO: Base dir: /var/jenkins_home/workspace/AuthenticationService
INFO: Working dir: /var/jenkins_home/workspace/AuthenticationService/.scannerwork
INFO: Load project settings for component key: 'com.authentication.microservice:authentication-service'
INFO: Load project settings for component key: 'com.authentication.microservice:authentication-service' (done) | time=18ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=57ms
INFO: Detected Jenkins
INFO: Load active rules
INFO: Load active rules (done) | time=724ms
INFO: Indexing files...
INFO: Project configuration:
INFO: 0 files indexed
INFO: 0 files ignored because of scm ignore settings
INFO: ------------- Run sensors on module AuthenticationService
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=41ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=11ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=1ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=0ms
INFO: Calculating CPD for 0 files
INFO: CPD calculation finished
INFO: Analysis report generated in 174ms, dir size=72 KB
INFO: Analysis report compressed in 16ms, zip size=9 KB
INFO: Analysis report uploaded in 37ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://35.195.88.51/dashboard?id=com.authentication.microservice%3Aauthentication-service
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://35.195.88.51/api/ce/task?id=AXI9sHtMRGaHU4KxYq-d
INFO: Analysis total time: 5.800 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 7.538s
INFO: Final Memory: 13M/33M
INFO: ------------------------------------------------------------------------
Finished: SUCCESS

此作业的SonarQube扫描仪配置如下:

enter image description here

我为sonar.sources属性尝试了不同的路径,但是没有任何效果。它给出相同的结果,或者在Jenkins构建中给出错误。

我现在真的很困,花了我整整一整天,我没有取得任何进展。如果有人可以帮助我,我将非常感激,谢谢!

编辑:这是我在sonar.sources属性中将/ src切换为/ src时的输出的最后一部分:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:02 min
[INFO] Finished at: 2020-05-23T21:34:12Z
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/pom.xml to com.authentication.microservice/authentication-service/0.0.1-SNAPSHOT/authentication-service-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/target/authentication-service-0.0.1-SNAPSHOT.jar to com.authentication.microservice/authentication-service/0.0.1-SNAPSHOT/authentication-service-0.0.1-SNAPSHOT.jar
channel stopped
[AuthenticationService] $ /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner/bin/sonar-scanner -Dsonar.host.url=http://35.195.88.51 ******** -Dsonar.projectName=AuthenticationService -Dsonar.projectVersion=1.0 -Dsonar.projectKey=com.authentication.microservice:authentication-service -Dsonar.sources=/var/jenkins_home/workspace/AuthenticationService/microservices/authentication-service/src -Dsonar.projectBaseDir=/var/jenkins_home/workspace/AuthenticationService
INFO: Scanner configuration file: /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.3.0.2102
INFO: Java 1.8.0_221 Oracle Corporation (64-bit)
INFO: Linux 4.14.138+ amd64
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Scanner configuration file: /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 7.9.1
INFO: Default locale: "en_US", source code encoding: "US-ASCII" (analysis is platform dependent)
WARN: SonarScanner will require Java 11+ to run starting in SonarQube 8.x
INFO: Load global settings
INFO: Load global settings (done) | time=186ms
INFO: Server id: A7EE8CF2-AXI9JaBwRGaHU4KxYo1w
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=63ms
INFO: Load/download plugins (done) | time=136ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=9ms
INFO: Project key: com.authentication.microservice:authentication-service
INFO: Base dir: /var/jenkins_home/workspace/AuthenticationService
INFO: Working dir: /var/jenkins_home/workspace/AuthenticationService/.scannerwork
INFO: Load project settings for component key: 'com.authentication.microservice:authentication-service'
INFO: Load project settings for component key: 'com.authentication.microservice:authentication-service' (done) | time=83ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=185ms
INFO: Detected Jenkins
INFO: Load active rules
INFO: Load active rules (done) | time=2071ms
INFO: Indexing files...
INFO: Project configuration:
INFO: 16 files indexed
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for java: Sonar way
INFO: ------------- Run sensors on module AuthenticationService
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=63ms
INFO: Sensor JavaSquidSensor [java]
INFO: Configured Java source version (sonar.java.source): none
INFO: JavaClasspath initialization
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 9.490s
INFO: Final Memory: 14M/34M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
org.sonar.java.AnalysisException: Please provide compiled classes of your project with sonar.java.binaries property
    at org.sonar.java.JavaClasspath.init(JavaClasspath.java:64)
    at org.sonar.java.AbstractJavaClasspath.getElements(AbstractJavaClasspath.java:280)
    at org.sonar.java.SonarComponents.getJavaClasspath(SonarComponents.java:209)
    at org.sonar.java.JavaSquid.<init>(JavaSquid.java:84)
    at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:87)
    at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:400)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:395)
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at com.sun.proxy.$Proxy0.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
    at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
ERROR: SonarQube scanner exited with non-zero code: 1
Finished: FAILURE
maven jenkins sonarqube sonarqube-scan
1个回答
0
投票

通过添加使其生效

sonar.java.binaries=**/target/classes  

声纳扫描仪的分析属性。我也将sonar.sources属性更改为

sonar.sources=microservices/authentication-service/src/main/java/

所以配置中的整个分析属性现在看起来像这样:

sonar.projectKey=com.authentication.microservice:authentication-service
sonar.projectName=AuthenticationService
sonar.projectVersion=1.0
sonar.sources=microservices/authentication-service/src/main/java/
sonar.java.binaries=**/target/classes
© www.soinside.com 2019 - 2024. All rights reserved.