Issue
I have a Jenkins job that will invoke SonarQube analysis on code pulled from a Bitbucket repository whenever there is any changes on the Bitbucket repository. At the moment, I was able to use the Confluence Publisher plugin to publish the URL of the build job to Confluence as a comment.
I was wondering if there is any way I could use Jenkins to screenshot the SonarQube analysis report (like in SonarQube web UI) and publish it directly to Confluence? (So that the user does not need to use the URL to go to the specific Jenkins build job, and then get the SonarQube analysis report URL, and navigate to the page to view the report)
Thank you.
Solution
Instead of using a screenshot, you can send a curl request from Jenkins to SonarQube REST API (5.3 and above) to get the project status from the quality gate after the code has been uploaded and analysed. The endpoint you'd likely want to use is: /api/qualitygates/project_status?prjectKey=<projectKey>&branch=<branch>
According to the web API docs:
Get the quality gate status of a project or a Compute Engine task. Either 'analysisId', 'projectId' or 'projectKey' must be provided The different statuses returned are: OK, WARN, ERROR, NONE. The NONE status is returned when there is no quality gate associated with the analysis. Returns an HTTP code 404 if the analysis associated with the task is not found or does not exist. Requires one of the following permissions: 'Administer System' 'Administer' rights on the specified project 'Browse' on the specified project
Once you have these results available, you can create a Jenkins user in Confluence and have Jenkins send a POST request to create a page or a comment with the results obtained.
Answered By - Ahmed Ramzi