- versions used: SonarQube 7.7, scanner 3.2.0 + Azure devops
- error observed (wrap logs/code around triple quote ``` for proper formatting)
Thesonar-project.properties
file in our project is not in the default location (project root). We have configured the AZ devops SonarCloud integration to specify our custom location for the file.
However the analysis task fails, stating that projectKey
has not been defined. The log suggests that the configuration file is not found at all - see second INFO
line:
##[section]Starting: Run Code Analysis
==============================================================================
Task : Run Code Analysis
Description : Run scanner and upload the results to the SonarCloud server.
Version : 1.5.1
Author : sonarsource
Help : This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.
[More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
[command]C:\WINDOWS\system32\cmd.exe /D /S /C "D:\agent\_work\_tasks\SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1\1.5.1\sonar-scanner\bin\sonar-scanner.bat"
INFO: Scanner configuration file: D:\agent\_work\_tasks\SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1\1.5.1\sonar-scanner\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 3.2.0.1227
INFO: Java 1.8.0_171 Oracle Corporation (32-bit)
INFO: Windows 10 10.0 x86
INFO: User cache: C:\WINDOWS\system32\config\systemprofile\.sonar\cache
INFO: SonarQube server 7.7.0
INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=255ms
INFO: Server id: BD367519-AWHW8ct9-T_TB3XqouNu
INFO: User cache: C:\WINDOWS\system32\config\systemprofile\.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=87ms
INFO: Load/download plugins (done) | time=271ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 3.022s
INFO: Final Memory: 19M/124M
INFO: ------------------------------------------------------------------------
##[error]ERROR: Error during SonarQube Scanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
ERROR: Error during SonarQube Scanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
##[error]D:\agent\_work\_tasks\SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1\1.5.1\sonar-scanner\bin\sonar-scanner.bat failed with return code: 1
##[section]Finishing: Run Code Analysis
- steps to reproduce
Configuration yaml for the SonarCloud task in AZ devops:
steps:
- task: SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
displayName: 'Prepare analysis on SonarCloud'
inputs:
SonarCloud: sonarcloud
organization: '**hidden**'
scannerMode: CLI
configFile: 'config/sonar/sonar-project.properties'
Contents of config/sonar/sonar-project.properties
:
# must be unique in a given SonarQube instance
sonar.projectKey=myProject:master
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=MyProject
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
# Additional properties that will be passed to the scanner,
# Put one key=value per line, example:
# sonar.exclusions=**/*.bin
sonar.inclusions=server/**/*,client/**/*
sonar.exclusions=node_modules/**/*,dist/**/*
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.typescript.lcov.reportPaths=coverage/lcov.info
sonar.typescript.tslint.reportPaths=ts-lint-report.json
# issue filtering
# the syntax for multiple criteria is missing from the documentation but we
# can supply a comma-separated list of criteria names in sonar.issue.ignore.multicriteria
# and then define each criteron as a pair of options
# sonar.issue.ignore.multicriteria.<name>.ruleKey and sonar.issue.ignore.multicriteria.<name>.resourceKey
sonar.issue.ignore.multicriteria=allowNonNullInTests
# typescript:S2966 - non-null operator should not be used
# disable for unit and integration tests, as non-null is normally checked
# with jest assertions but TypeScript does not detect that, so non-null
# operator relieves the code of unnecessary extra checks
sonar.issue.ignore.multicriteria.allowNonNullInTests.ruleKey=typescript:S2966
sonar.issue.ignore.multicriteria.allowNonNullInTests.resourceKey=**/__*tests__/*
- potential workaround: put properties file at root and set
configFile: 'sonar-project.properties
in the AZ devops configuration. As far I have been able to assess, it is the only place - and file name - that does work.