Azure DevOps SonarCloud Prepare Analysis

Using the latest version of Azure DevOps build pipelines and the “Prepare Analysis” step.

Unfortunately, the “Run Code Analysis” reports an error that it cannot find the sonar.projectKey.

[command]C:\Windows\system32\cmd.exe /D /S /C "D:\agent\_work\_tasks\SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1\1.6.2\sonar-scanner\bin\sonar-scanner.bat"
(node:2552) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:2552) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:2552) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:2552) Warning: Use Cipheriv for counter mode of aes-256-ctr
INFO: Scanner configuration file: D:\agent\_work\_tasks\SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1\1.6.2\sonar-scanner\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 3.3.0.1492
INFO: Java 12.0.1 Oracle Corporation (64-bit)
INFO: Windows Server 2016 10.0 amd64
INFO: User cache: C:\Windows\ServiceProfiles\NetworkService\.sonar\cache
INFO: SonarQube server 7.8.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=646ms
INFO: Server id: BD367519-AWHW8ct9-T_TB3XqouNu
INFO: User cache: C:\Windows\ServiceProfiles\NetworkService\.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=158ms
INFO: Load/download plugins (done) | time=330ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 3.555s
INFO: Final Memory: 6M/24M
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.6.2\sonar-scanner\bin\sonar-scanner.bat failed with return code: 1
##[section]Finishing: Run Code Analysis

You’ll see above that it cannot find the project root configuration file.

However, in my “Prepare Analysis” step, I’ve got the following configuration:

Way to run analysis: Use standalone scanner
Mode: Store configuration with my source code
Settings file: Browser/sonar-project.properties

I’ve also tried the full project path for settings file: $(System.DefaultWorkingDirectory)/Browser/sonar-project.properties

However, it’s not pulling the file at all.

Upon future exploration (I edited the analyze.js to echo out parameters):

Current environment variables (i’ve removed private content):

agent.jobstatus=Succeeded
AGENT_BUILDDIRECTORY=D:\agent\_work\6
AGENT_DISABLELOGPLUGIN_TESTFILEPUBLISHERPLUGIN=true
AGENT_DISABLELOGPLUGIN_TESTRESULTLOGPLUGIN=true
AGENT_HOMEDIRECTORY=D:\agent
AGENT_ID=7
AGENT_JOBNAME=Agent job 1
AGENT_JOBSTATUS=Succeeded
AGENT_MACHINENAME=C-A-TFSAGENT-01
AGENT_NAME=C-A-TFSAGENT-01
AGENT_OS=Windows_NT
AGENT_OSARCHITECTURE=X64
AGENT_RETAINDEFAULTENCODING=false
AGENT_ROOTDIRECTORY=D:\agent\_work
AGENT_SERVEROMDIRECTORY=D:\agent\externals\vstsom
AGENT_TEMPDIRECTORY=D:\agent\_work\_temp
AGENT_TOOLSDIRECTORY=D:\agent\_work\_tool
AGENT_VERSION=2.148.0
AGENT_WORKFOLDER=D:\agent\_work
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming
AZURE_HTTP_USER_AGENT=VSTS_d6de2d63-a22d-4f21-aa65-1a25daefa0c9_build_9_0
BUILDCONFIGURATION=debug
BUILDPLATFORM=any cpu
BUILD_ARTIFACTSTAGINGDIRECTORY=D:\agent\_work\6\a
BUILD_BINARIESDIRECTORY=D:\agent\_work\6\b
BUILD_BUILDID=347
BUILD_BUILDNUMBER=20190528.5-develop-ci
BUILD_BUILDURI=vstfs:///Build/Build/347
BUILD_CONTAINERID=602176
BUILD_DEFINITIONNAME=A...y #develop --CI
BUILD_DEFINITIONVERSION=42
BUILD_QUEUEDBY=Joshua Davis
BUILD_QUEUEDBYID=a7ba5ac2-e12a-6ebe-8e25-3962b1dab8e0
BUILD_REASON=Manual
BUILD_REPOSITORY_CLEAN=true
BUILD_REPOSITORY_GIT_SUBMODULECHECKOUT=False
BUILD_REPOSITORY_ID=48d3b8dd-9e47-47b4-904e-6533d4cc5722
BUILD_REPOSITORY_LOCALPATH=D:\agent\_work\6\s
BUILD_REPOSITORY_NAME=A...y
BUILD_REPOSITORY_PROVIDER=TfsGit
BUILD_REPOSITORY_URI=https://***@dev.azure.com/.../_git/...
BUILD_REQUESTEDFOR=Joshua Davis
BUILD_REQUESTEDFOREMAIL=me@jdav.is
BUILD_REQUESTEDFORID=a7ba5ac2-e12a-6ebe-8e25-3962b1dab8e0
BUILD_SOURCEBRANCH=refs/heads/develop
BUILD_SOURCEBRANCHNAME=develop
BUILD_SOURCESDIRECTORY=D:\agent\_work\6\s
BUILD_SOURCEVERSION=ca0f8291ebeb466d20829e9bac2465051a4748d0
BUILD_SOURCEVERSIONAUTHOR=Joshua Davis
BUILD_SOURCEVERSIONMESSAGE=Updated sonar-project.properties
BUILD_STAGINGDIRECTORY=D:\agent\_work\6\a
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMMON_TESTRESULTSDIRECTORY=D:\agent\_work\6\TestResults
COMPUTERNAME=C-A-TFSAGENT-01
ComSpec=C:\Windows\system32\cmd.exe
ENDPOINT_URL_SYSTEMVSSCONNECTION=https://dev.azure.com/.../
java=C:\Program Files\Java\jdk-12.0.1\bin\java.exe
LOCALAPPDATA=C:\Windows\ServiceProfiles\NetworkService\AppData\Local
MSDEPLOY_HTTP_USER_AGENT=VSTS_d6de2d63-a22d-4f21-aa65-1a25daefa0c9_build_9_0
NUGETEXETOOLPATH=D:\agent\_work\_tool\NuGet\4.4.1\x64\nuget.exe
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
PARAMETERS_ARTIFACTNAME=drop
Path=D:\agent\_work\_tool\NuGet\4.4.1\x64;D:\agent\externals\git\cmd;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\nodejs\;C:\Program Files\dotnet\;C:\Program Files\Java\jdk-12.0.1\bin\;C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Microsoft\WindowsApps
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 63 Stepping 0, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=3f00
PROCPARAM_ARTIFACTNAME=drop
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=%ProgramFiles%\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
PUBLIC=C:\Users\Public
SONARQUBE_SCANNER_MODE=CLI
SONARQUBE_SCANNER_PARAMS={"sonar.host.url":"https://sonarcloud.io/","sonar.login":***,"sonar.organization":"....","project.settings":"D:\\agent\\_work\\6\\s\\Browser\\sonar-project.properties"}
SYSTEM=build
SystemDrive=C:
SystemRoot=C:\Windows
SYSTEM_ARTIFACTSDIRECTORY=D:\agent\_work\6\a
SYSTEM_COLLECTIONID=d6de2d63-a22d-4f21-aa65-1a25daefa0c9
SYSTEM_COLLECTIONURI=https://dev.azure.com/.../
SYSTEM_CULTURE=en-US
SYSTEM_DEBUG=false
SYSTEM_DEFAULTWORKINGDIRECTORY=D:\agent\_work\6\s
SYSTEM_DEFINITIONID=9
SYSTEM_DEFINITIONNAME=A...y #develop --CI
SYSTEM_HOSTTYPE=build
SYSTEM_ISSCHEDULED=False
SYSTEM_JOBATTEMPT=1
SYSTEM_JOBDISPLAYNAME=Agent job 1
SYSTEM_JOBID=275f1d19-1bd8-5591-b06b-07d489ea915a
SYSTEM_JOBIDENTIFIER=Job_1.__default
SYSTEM_JOBNAME=__default
SYSTEM_JOBPARALLELISMTAG=Private
SYSTEM_JOBPOSITIONINPHASE=1
SYSTEM_PHASEATTEMPT=1
SYSTEM_PHASEDISPLAYNAME=Agent job 1
SYSTEM_PHASEID=2f97f1d8-943c-5cda-8782-cbcebf2b3d67
SYSTEM_PHASENAME=Job_1
SYSTEM_PIPELINESTARTTIME=2019-05-28 19:54:51+00:00
SYSTEM_PLANID=78ce0d38-1bb2-4b9c-a271-e0175e6b010a
SYSTEM_PULLREQUEST_ISFORK=False
SYSTEM_SERVERTYPE=Hosted
SYSTEM_STAGEATTEMPT=1
SYSTEM_STAGEDISPLAYNAME=__default
SYSTEM_STAGEID=96ac2280-8cb4-5df5-99de-dd2da759617d
SYSTEM_STAGENAME=__default
SYSTEM_TASKDEFINITIONSURI=https://dev.azure.com/.../
SYSTEM_TASKDISPLAYNAME=Run Code Analysis
SYSTEM_TASKINSTANCEID=fc3e0b25-4ec6-50a7-db6b-69f789852e71
SYSTEM_TASKINSTANCENAME=SonarCloudAnalyze
SYSTEM_TEAMFOUNDATIONCOLLECTIONURI=https://dev.azure.com/.../
SYSTEM_TEAMFOUNDATIONSERVERURI=https://dev.azure.com/.../
SYSTEM_TEAMPROJECT=A...y
SYSTEM_TEAMPROJECTID=788aef24-6e05-4071-8704-97fbadf190b3
SYSTEM_TIMELINEID=78ce0d38-1bb2-4b9c-a271-e0175e6b010a
SYSTEM_TOTALJOBSINPHASE=1
SYSTEM_WORKFOLDER=D:\agent\_work
TASK_DISPLAYNAME=Run Code Analysis
TEMP=C:\Windows\SERVIC~2\NETWOR~1\AppData\Local\Temp
TF_BUILD=True
TMP=C:\Windows\SERVIC~2\NETWOR~1\AppData\Local\Temp
USERDOMAIN=CAPSTONE
USERNAME=C-A-TFSAGENT-01$
USERPROFILE=C:\Windows\ServiceProfiles\NetworkService
VSTS_PROCESS_LOOKUP_ID=vsts_a5418459-e9a1-4779-b943-eacd0fef5c63
windir=C:\Windows

The java exec command line (%JAVA_EXEC% -Djava.awt.headless=true %SONAR_SCANNER_DEBUG_OPTS% %SONAR_SCANNER_OPTS% -cp "%SONAR_SCANNER_HOME%\lib\sonar-scanner-cli-3.3.0.1492.jar" "-Dscanner.home=%SONAR_SCANNER_HOME%" "-Dproject.home=%PROJECT_HOME%" org.sonarsource.scanner.cli.Main %*) looks like this in the task runner logs:

D:\agent\_work\6\s>"C:\Program Files\Java\jdk-12.0.1\bin\java.exe" -Djava.awt.headless=true   -cp "D:\agent\_work\_tasks\SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1\1.6.2\sonar-scanner\bin\..\lib\sonar-scanner-cli-3.3.0.1492.jar" "-Dscanner.home=D:\agent\_work\_tasks\SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1\1.6.2\sonar-scanner\bin\.." "-Dproject.home=D:\agent\_work\6\s" org.sonarsource.scanner.cli.Main  

There’s two spaces between java.awt.headless=true and -cp.

Bottom line:
%SONAR_SCANNER_DEBUG_OPTS% and %SONAR_SCANNER_OPTS% are not set for the Analyze step.

Hi Joshua,

We opened a ticket to track this issue on our side : https://jira.sonarsource.com/browse/VSTS-171

It appears that the project.settings is not well parsed while calling our internal command line tool

We’ll have a look at that.

Thanks,

Hi,

A newest version of the extension has been deployed (1.8.0). You can now use the properties file along with the standalone scanner configuration.

Please let us know if you see any issue with that.

Thanks.

Mickaël