Previously working SonarCloud integration stopped working

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.

Hey there.

Can you share the logs where you see the error? I’m not familiar with this exact error message (I don’t think it comes from us).

Hi Colin,


Step 3/9: Start Sonar Scanner for PR (PowerShell)
  PowerShell Executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  Working directory: C:\BuildAgent\work\8a1c0cf1e7f7ad4d
  Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  PowerShell arguments: -NoProfile, -NonInteractive, -ExecutionPolicy, ByPass, -File, C:\BuildAgent\temp\buildTmp\powershell15432259423738548789.ps1

    c:\sonar-scanner-msbuild-\SonarScanner.MSBuild.exe begin                                         `
     /o:carterra                                                  `
     /k:Navigator                                              `
     /                               `
     /d:sonar.inclusions=Navigator*/**/*.cs                          `
     /d:sonar.cs.dotcover.reportsPaths=dotCover.html        `
     /d:sonar.pullrequest.provider=bitbucketcloud                   `
     /d:sonar.pullrequest.branch=bugfix/LSA-2896-roi-mask-not-updated-by-spot-fi                 `
     /d:sonar.pullrequest.base=release/2.1.2    `
     /d:sonar.pullrequest.bitbucketcloud.repository="[redacted]"  `
     /d:sonar.pullrequest.bitbucketcloud.owner="[redacted]" `
  C:\BuildAgent\temp\buildTmp\powershell15432259423738548789.ps1 : Failed to start scanner; build step failed
      + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershell15432259423738548789.ps1
  Process exited with code 1

Thanks for any help you can give.


Have you written some custom powershell for this step? If so can you share it here?

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.

 ## 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.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
   Write-Error "Failed to start scanner; build step failed"
   exit 1

SonarScannerExe is defined as c:\sonar-scanner-msbuild-\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.

These are the options in the main branch:

 %SonarScannerExe% begin `
   /o:%SonarOrg% `
   /k:%SonarProject% `
   / `
   /d:sonar.login=%SonarToken% `
   /n:%SonarProject% `
   /v:%VERSION% `
   / `
   /d:sonar.inclusions=%SonarInclusions% `
   /d:sonar.exclusions=%SonarExclusions% `

The differences are we don’t have this in the PR branch:

   /n:%SonarProject% `
   /v:%VERSION% `

And we do have this in the PR branch:

   /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%"  `

Again, this was working for years up until last week. Nothing was changed that we know of.

Any ideas?

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.