Ant build with cli parameters fails but adding sonar.login to build.xml works

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • Community Edition Version 8.6.1 (build 40680), Sonar Scanner for ant 2.7
    Got Docker installation for Sonarqube server side.
  • what are you trying to achieve
    Trying to get the example project working SonarScanner for Ant | SonarQube Docs
  • what have you tried so far to achieve this
    Got the project listed here and tried ant sonar for sample project listed here.

ant sonar -Dsonar.login=authToken

Configured auth token in server.

Not authorized. Analyzing this project requires to be authenticated. Please provide the values of the properties sonar.login and sonar.password.

I edited build.xml and added

<property name="sonar.login" value="authToken"/>

Running ant sonar worked.

Am I doing something wrong when I try to add the -Dsonar.login via CLI?

Hi,

I don’t think so; you’re doing what we’ve said in other places will work. But keep in mind that in those other places you’re directly invoking analysis. In this case you’re invoking Ant, which triggers analysis. Ant has no way of knowing that it should pass its command line parameters into that specific command in that specific target.

So you probably have to explicitly catch the variable and pass to your analysis command or do as you’ve done & hard-code it.

Make sense?

 
Ann