I have a jenkins pipeline which scans the project with command
/opt/sonar-scanner/bin/sonar-scanner
but after the completion of sonarscan in the jenkins pipeline the results are not immediately reflected in the sonarqube because my project is very large it takes at least 10 minutes in the background task
So I am looking for a jenkins stage which continuously checks weather the sonar scan is completed in the background or not. Once completed I need to extract the scan details from sonarqube which I have completed.
There are a couple of ways to do this.
If you're using a Jenkins scripted pipeline, you should be using the "withSonarQubeEnv" and "waitForQualityGate" pipeline steps, and you should have a webhook configured in SonarQube to connect to Jenkins. If this is all in place and working, then "waitForQualityGate" completes when the webhook is executed, which is executed when the background task is complete.
That should be all you need in most cases. Curiously, in my enterprise, the webhook from sonarqube to jenkins doesn't work (stopped working one day when some Jenkins security configurations were changed, and no one has ever figured out why). I gave up waiting for that to be fixed, so I had to dive into the details.
The scan will create a file called "report-task.txt". You'll have to figure out where it is. It might be at "target/sonar/report-task.txt". This file is structured like a Java properties file, but it only has one property that you care about (it might be the only property defined in the file), called "ceTaskId".
Once you have that value, you have to make a call to the SonarQube REST api: "/api/ce/task?id=". Look at the WebApi documentation for information about this endpoint. This will have a "task.status" property. If the value is not equal to "IN_PROGRESS" or "PENDING", then the task is complete.