Java プロジェクトがあり、それを SonarCloud と統合したい 公式の手順に従います。
SonarQube Scanner を使用したコードの検査 #
コードを検査する前に、次のことを行う必要があります。
- SonarCloud でアカウントのユーザー認証トークンを作成します。
- このトークンを暗号化する travis encrypt abcdef0123456789 か、リポジトリ設定で SONAR_TOKEN を定義します
- プロジェクトをプッシュする SonarCloud.io 組織を見つけて、そのキーを取得します
- プロジェクトの 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 にアップロードする権限がないように思えます。トークンまたは一部のソナー構成に問題がありますか。