10

Java プロジェクトがあり、それを SonarCloud と統合したい 公式の手順に従います。

SonarQube Scanner を使用したコードの検査 #

コードを検査する前に、次のことを行う必要があります。

  1. SonarCloud でアカウントのユーザー認証トークンを作成します。
  2. このトークンを暗号化する travis encrypt abcdef0123456789 か、リポジトリ設定で SONAR_TOKEN を定義します
  3. プロジェクトをプッシュする SonarCloud.io 組織を見つけて、そのキーを取得します
  4. プロジェクトの sonar-project.properties ファイルを作成します (ドキュメントを参照してください)。次に、次の行を .travis.yml ファイルに追加して、分析をトリガーします。

travis.yml ファイルに追加します

 addons:
  sonarcloud:
    organization: "xelian-github"
    token:
      secure: ${SONAR_TOKEN}
    branches:
      - master
script:
  # other script steps might be done before running the actual analysis
  - sonar-scanner

SONAR_TOKEN は、SonarCloud からのキーを指す Travis CI の変数です (暗号化されていません)。 ここに画像の説明を入力 SonarCloud から権限を追加します ここに画像の説明を入力

しかし、travis ビルドを開始すると、次のエラーが発生します。

Setting environment variables from repository settings
$ export SONAR_TOKEN=[secure]

 ....
ERROR: Error during SonarQube Scanner execution
ERROR: You're only authorized to execute a local (preview) SonarQube analysis without pushing the results to the SonarQube server. Please contact your SonarQube administrator.
ERROR: 
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.

travis には、結果を SonarCloud にアップロードする権限がないように思えます。トークンまたは一部のソナー構成に問題がありますか。

4

2 に答える 2

0

最後に、解決策を見つけます。ルート パスに yml ファイルを追加する必要があります。

sonar-project.properties

# Required metadata
sonar.projectKey=java-sonar-runner-simple:master
sonar.projectName=Rss-service
sonar.projectVersion=1.0

# Comma-separated paths to directories with sources (required)
sonar.sources=/microservice-application/rss-reader-service/src/main/java
sonar.java.binaries=/microservice-application/rss-reader-service/target/classes

# Language
sonar.language=java

# Encoding of the source files
sonar.sourceEncoding=UTF-8

そして、travis.yml に以下を追加します: スクリプト:

  # other script steps might be done before running the actual analysis
  - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar

編集

sonar-project.properties は必要ありません。Maven の目標だけが意味を成します。

于 2017-09-28T17:31:16.697 に答える