Sonar Gradle task fails with error "SONAR4BAMBOO: was not able to find a SonarQube result URL"
Asked by Kira Resari:

I have just installed the Sonar for Bamboo plugin, and have trouble getting it to work.

I have followed the steps on <https://mibexsoftware.atlassian.net/wiki/spaces/MSS/pages/1339883529/Getting+started+with+Sonar+for+Bamboo> to the best of my abilities, but when I try to run the build, the Sonar Gradle task fails with the following, not very descriptive reply:

```
15-May-2020 11:05:02 Starting task 'SonarQube' of type 'ch.mibex.bamboo.sonar4bamboo:sonar4bamboo.gradletask'
15-May-2020 11:05:02 SONAR4BAMBOO: No branch target found, will not configure sonar.branch.target.
15-May-2020 11:05:02
Beginning to execute external process for build 'Project - Module - Build and Unit tests #71 (PRO-MOD-JOB1-71)'
... running command line:
./gradlew sonarqube --info -Dsonar.host.url=http://localhost:9000 -Dsonar.login=****** -Dsonar.password=****** ... in: /var/atlassian/application-data/bamboo/xml-data/build-dir/PRO-MOD-JOB1
... using extra environment variables:

[Long list of environment variables]

15-May-2020 11:05:02 Failing task since return code of [./gradlew sonarqube --info -Dsonar.host.url=http://localhost:9000 -Dsonar.login=****** -Dsonar.password=****** was -1 while expected 0
15-May-2020 11:05:02 SONAR4BAMBOO: was not able to find a SonarQube result URL
15-May-2020 11:05:02 Finished task 'SonarQube' with result: Failed
```

My environment setup is that I have Bamboo and SonarQube running on the same server on different ports. SonarQube is running in a Docker Container that is accessible via port 9000, and I can successfully log in to its web interface, so I can say for sure that it's accessible.

However, I have no idea why the Sonar Gradle build step fails, primarily because apart from the above lines no error is generated, so I don't have any idea what could be wrong here.

Any advice on this would be greatly appreciated.


Answers:
author: Kira Resari
body: I figured out what was missing. All the other build steps had a working subdirectory set, and once I set that to the same value for the Sonar Gradle step, it worked fine.

By the way, is there a way to globally set the working subdirectory for the entire build? This has happened so many times now with different steps, it's actually embarrassing that it wasn't the first thing I tried. =\<,\<=

comments: author: sushmita bhandari
body: Hi Kira,

Could you tell what did you write in working subdirectory because i'm also getting this:

```
SONAR4BAMBOO: was not able to find a SonarQube result URL
Finished task 'SonarQube' with result: Failed
```


author: Kira Resari
body: Well, that will probably not help you much, since it is just one word.

So I'll try to elaborate: We have a project structure that looks like this:

```
project
?module-a
?module-b
?module-c
```

The build for module-a has "module-a" written in the "working subdirectory" field of all its build steps, the build for module-b has "module-b" written in all of them, etc...

It's literally just "module-a", without any /, \\, . or whatever


author: Michael R?egg _Mibex Software_
body: Hi,

The app fails when it tries to parse the build log for the result URL to be able to show a link to the SonarQube analysis results on the Bamboo build page. Do you see a message like

```
17:01:02.199 INFO  - ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/MY-GRADLE-JOB1
```

in your build log? That is what the app is looking for, and otherwise it will fail with the above message. This could be due to the SonarQube analysis not being successful which I cannot see in your log excerpt.

Thanks,

Michael (app vendor)

comments: author: Kira Resari
body: Nope, the error was actually that the working subdirectory was not set correctly. It took me a while to figure this out, though, since the Sonar Gradle task did not display any indication of this in its log. The above messages were literally all the messages that Sonar Gradle gave me, so I just did not know what went wrong.


Tags: app

sonar

sonarqube