How to use API for getting build details in shell script?


(Ashutosh) #1

Hello There,

I want to write a shell script to login and get bugs for a project. I want the dashboard values like bugs, Vulnerabilities, code smells and coverage.
The url of dashboard is:

Here is what I found online: curl -u MY_LOGIN:MY_PASSWORD

But when I use it in terminal: curl -X POST -u username:password

I get an error: {“errors”:[{“msg”:“Authentication is required”}]}.

Here is the URL from which I used the WebAPI:

Please help me use WebAPI in Sonarqube.

Basically What I want to achieve is that I’m using a sonarqube plugin in Jenkins, so I use extended email plugin to send email for job execution and in that email I want to give details like number of bugs in the repository after the build.

Is there any other way?

(Ashutosh) #2

Finally after reading the documentation carefully, I got the values. Here is the script that I created:

vul=$(curl -sX GET -u username:password ‘’);
bug=$(curl -sX GET -u username:password ‘’);
no_vul=$(echo $vul | jq -r .total);
no_bug=$(echo $bug | jq -r .total);
echo “Total number of VULNERABILITIES are $no_vul”
echo “Total number of BUGS are $no_bug”

Here is the API documentation URL:

(Nicolas Bontoux) #3

Thanks for the follow-through. Quick comment on this:

Note that the WebAPI documentation is embedded in all SonarQube instances ! To all readers: it’s important to check the documentation in the actual instance you’re using, to be sure that what you’re reading corresponds to the SonarQube version you’ll be querying.