VSTS Prepare Analysis Configuration can't read settings file


(Norman) #1

I’m using the sonarqube analysis for our Angular application to analyze the typescript source code.

The Task (Marketplace Extension) is Version 4.

When using the configuration option “store configuration with my source source (sonar-project.properties)” the build fails, because SonarQube can’t read the main project configuration even though it is configured in the properties file.

I tried both relative and absolute path configurations. This is the latest: "${System.DefaultWorkingDirectory}/vsts/build/sonar-project.properties"

ERROR: Error during SonarQube Scanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.sources
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
C:\vsts-agent\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\4.3.0\sonar-scanner\bin\sonar-scanner.bat failed with return code: 1

Even enabling the debug flag on the build pipeline didn’t provide anymore information except that there is no information being printed about the variables being loaded.

I also had a look at the typescript code and noticed that the properties might not be properly loaded that way. The confusing issue was, that even with debug enabled, the tl.getInput() calls did not log their intended debug output.

According to this piece of code (Scanner.ts from sonar-scanner-vsts repo)

  public toSonarProps() {
    if (this.cliMode === 'file') {
      return { [PROP_NAMES.PROJECTSETTINGS]: this.data.projectSettings };
    return {
      [PROP_NAMES.PROJECTKEY]: this.data.projectKey,
      [PROP_NAMES.PROJECTNAME]: this.data.projectName,
      [PROP_NAMES.PROJECTVERSION]: this.data.projectVersion,
      [PROP_NAMES.PROJECTSOURCES]: this.data.projectSources

The projectSettings (which is just the filename of the settings) is placed in the PROJECTSETTINGS variable, but this seems to be ignored by sonarqube.

Is there any way to debug this any further?

It would be really helpful for us, because we don’t want to inline the sonar properties in the build pipeline but instead have them as a file in our git repo.

(Emre Dundar) #2

Hi Norman,

Could you share your sonar-project.properties (to check project key and sources properties)?

Do you have a line in your build log like this one:

INFO: Project root configuration file:

Could you also share this line?

(Norman) #3

Hi Emre,

unfortunately this is the project root I get:
INFO: Project root configuration file: NONE

even though after the prepare analysis task is finished, those two task variables are added to my build/agent

SONARQUBE_SCANNER_PARAMS               = {"sonar.host.url":"<my-sonarqube.server>","sonar.login":"<some-unique-id>","project.settings":"C:\\vsts-agent\\_work\\41\\s\\vsts\\build\\sonar-project.properties"}

And my sonar-project.properties in the vsts/build/ folder in my repo:

sonar.projectName=My Project Name

Does this help you?
Could it be that for some reason the run code analysis task does not read the right environment / task variable?

(Emre Dundar) #4

Hi Norman,

I think you are right. Your configuration is ok.
VSTS “Run Code Analysis” task ignores whatever you write as “Settings File” on this window.

“Run Code Analysis” task just looks the root directory of your repository. If there is a sonar-project.properties file exists, analysis continues successfully. It doesn’t search and use the file you set as Settings File.

For a quick solution, just put your sonar-project.properties file on the root folder of your repo.
And you can leave empty this property: Settings File :slight_smile: The task doesn’t know it…

INFO: Project root configuration file: C:\agent\_work\1\s\sonar-project.properties

(Norman) #5

Thank you! That serves as a workaround for now. Can you open a Jira Issue for the task to use the whole path provided? (either absolute or relative from working dir) - That would be great! I tried to access the SQ Jira, but I can’t create issues on my own.