Our SCC is Bitbucket and CI build system is TeamCity. We have SonarCloud setup in our build pipeline and it’s been working fine for several years. Suddenly on Thursday it quite working. There have been no intentional changes to anything in the build system.
On pull request pages where it normally gives the SonarCloud results now says “Not analyzed on SonarCloud yet”.
In the build logs, the step that starts the sonar scanner has an error stating “Failed to start scanner; build step failed” followed by a WriteErrorException report. Of course subsequent scanner related steps fail too.
Any suggestions as to how to diagnose and/or fix the problem? I’m not sure where to even start looking.
Have you written some custom powershell for this step? If so can you share it here?
Sure. It’s just a simple wrapper around the SonarStart executable for logging purposes.
try
{
## save the command to a variable to print it out for easier debugging
## nothing can follow the ` character on multiline commands so watch for that
$start_scanner =
{
%SonarScannerExe% begin `
/o:%SonarOrg% `
/k:%SonarProject% `
/d:sonar.host.url=%SonarHostUrl% `
/d:sonar.login=%SonarToken% `
/d:sonar.inclusions=%SonarInclusions% `
/d:sonar.exclusions=%SonarExclusions% `
/d:sonar.cs.dotcover.reportsPaths=%SonarCoverageReport% `
/d:sonar.pullrequest.provider=bitbucketcloud `
/d:sonar.pullrequest.key=%BITBUCKET_PR_ID% `
/d:sonar.pullrequest.branch=%BITBUCKET_BRANCH% `
/d:sonar.pullrequest.base=%BITBUCKET_PR_DESTINATION_BRANCH% `
/d:sonar.pullrequest.bitbucketcloud.repository="%BITBUCKET_REPO_UUID%" `
/d:sonar.pullrequest.bitbucketcloud.owner="%BITBUCKET_REPO_OWNER_UUID%" `
}
##echo the command so the variable expansions can be seen in the log
echo $start_scanner
##execute the command
& $start_scanner
}
catch
{
Write-Error "Failed to start scanner; build step failed"
exit 1
}
SonarScannerExe is defined as c:\sonar-scanner-msbuild-5.8.0.52797-net46\SonarScanner.MSBuild.exe
Some more information: we have two steps for different contexts. One is used for our main branch and the sonarcloud integration works there. The one that doesn’t work is for PR branches. The difference is in options that are passed to SonarScanner. The PR branch is listed above.
I would suggest adjusting the PowerShell so that you can see the actual error is being produced. Right now, the only output you’ve created is to say that the scanner fails, but not actually why he scanner fails (can’t find the executable, bad parameters, etc.)
Just following up on this… we left it alone for a week or so (busy with other things) and it resolved itself without any additional action on our part.