Sonarscanner + TeamCity + Git Issue

I’m getting a baffling error - Not inside a Git work tree when I try to run an analysis using the msbuild scanner. This only seems to happen on my TeamCity build - if I run an analysis locally, I get the expected Git blame, etc.

If I try to let the build auto-detect the source provider, it fails to do so with WARN: SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.scm.provider to define SCM of your project

I’m using SonarScanner for MSBuild 4.3.1 on Ubuntu, with .NET Core 2.1.403. I’m not sure what’s going wrong - I can pass in the branch in the sonarqube command line, and it shows up fine in the UI, but there’s clearly not a proper branch relationship (for example, the same issues are duplicated between master and development).

dotnet sonarscanner begin /k:"Server" /n:"Server" /v:"%build.number%" /d:sonar.login="%sonar.key%" /d:sonar.host.url="http://sonarqubeserver:9000" /d:sonar.cs.opencover.reportsPaths="coverage/*.xml" /d:sona
r.javascript.lcov.reportPaths="assets/coverage/lcov.info" /d:sonar.branch.name="development" 
dotnet build mysolution.sln
dotnet sonarscanner end /d:sonar.login="%sonar.key%"

I’ve tried also explicitly including /d:sonar.scm.provider=“git” /d:sonar.sources="%teamcity.build.checkoutDir%/server" but it doesn’t make a difference.

Where should I go from here? Is there some obvious setting I’m missing?

I managed to get a full debug log dump using -X. Not sure if this is helpful to someone (it’s not obvious to me where to go next).

Full debug log behind the snip

[19:31:24] [Step 2/6] 19:31:24.888 INFO: ------------- Scan Server

[19:31:24] [Step 2/6] 19:31:24.919 DEBUG: Installed core extension: branch-scanner

[19:31:25] [Step 2/6] 19:31:24.988 INFO: Base dir: /opt/teamcity/work/e6c1f1c1b12e6dea/server

[19:31:25] [Step 2/6] 19:31:24.988 INFO: Working dir:
/opt/teamcity/work/e6c1f1c1b12e6dea/server/.scannerwork

[19:31:25] [Step 2/6] 19:31:24.989 INFO: Source paths: src

[19:31:25] [Step 2/6] 19:31:24.989 INFO: Test paths: test

[19:31:25] [Step 2/6] 19:31:24.990 INFO: Source encoding: UTF-8, default locale: en_US

[19:31:25] [Step 2/6] 19:31:24.991 INFO: SCM collecting changed files in the branch

[19:31:25] [Step 2/6] 19:31:25.007 INFO: ------------------------------------------------------------------------

[19:31:25] [Step 2/6] 19:31:25.007 INFO: EXECUTION FAILURE

[19:31:25] [Step 2/6] 19:31:25.007 INFO: ------------------------------------------------------------------------

[19:31:25] [Step 2/6] 19:31:25.007 INFO: Total time: 2.376s

[19:31:25] [Step 2/6] 19:31:25.080 INFO: Final Memory: 59M/379M

[19:31:25] [Step 2/6] 19:31:25.080 INFO: ------------------------------------------------------------------------

[19:31:25] [Step 2/6] 19:31:25.080 ERROR: Error during SonarQube Scanner execution

[19:31:25] [Step 2/6] java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.phases.AbstractPhaseExecutor

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer.getComponentByType(ComponentContainer.java:281)

[19:31:25] [Step 2/6] at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:166)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)

[19:31:25] [Step 2/6] at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:300)

[19:31:25] [Step 2/6] at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:295)

[19:31:25] [Step 2/6] at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:269)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)

[19:31:25] [Step 2/6] at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)

[19:31:25] [Step 2/6] at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:82)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)

[19:31:25] [Step 2/6] at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:131)

[19:31:25] [Step 2/6] at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)

[19:31:25] [Step 2/6] at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:111)

[19:31:25] [Step 2/6] at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)

[19:31:25] [Step 2/6] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

[19:31:25] [Step 2/6] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

[19:31:25] [Step 2/6] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

[19:31:25] [Step 2/6] at java.lang.reflect.Method.invoke(Method.java:498)

[19:31:25] [Step 2/6] at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)

[19:31:25] [Step 2/6] at com.sun.proxy.$Proxy0.execute(Unknown Source)

[19:31:25] [Step 2/6] at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)

[19:31:25] [Step 2/6] at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)

[19:31:25] [Step 2/6] at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)

[19:31:25] [Step 2/6] at org.sonarsource.scanner.cli.Main.execute(Main.java:77)

[19:31:25] [Step 2/6] at org.sonarsource.scanner.cli.Main.main(Main.java:61)

[19:31:25] [Step 2/6] Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.phases.PostJobsExecutor

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)

[19:31:25] [Step 2/6] 19:31:25.082 DEBUG: Execution getVersion

[19:31:25] [Step 2/6] at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)

[19:31:25] [Step 2/6] 19:31:25.082 DEBUG: Execution stop

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)

[19:31:25] [Step 2/6] … 29 more

[19:31:25] [Step 2/6] Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.bootstrap.ScannerExtensionDictionnary

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)

[19:31:25] [Step 2/6] … 43 more

[19:31:25] [Step 2/6] Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.sensor.DefaultSensorContext

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)

[19:31:25] [Step 2/6] … 57 more

[19:31:25] [Step 2/6] Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)

[19:31:25] [Step 2/6] … 71 more

[19:31:25] [Step 2/6] Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.StatusDetection

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)

[19:31:25] [Step 2/6] … 85 more

[19:31:25] [Step 2/6] Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.StatusDetection

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:621)

[19:31:25] [Step 2/6] at org.picocontainer.containers.ImmutablePicoContainer.getComponent(ImmutablePicoContainer.java:40)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:718)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)

[19:31:25] [Step 2/6] … 99 more

[19:31:25] [Step 2/6] Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scm.ScmChangedFiles

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)

[19:31:25] [Step 2/6] at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)

[19:31:25] [Step 2/6] at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)

[19:31:25] [Step 2/6] at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)

[19:31:25] [Step 2/6] at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)

[19:31:25] [Step 2/6] at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)

[19:31:25] [Step 2/6] … 104 more

[19:31:25] [Step 2/6] Caused by: Not inside a Git work tree: /opt/teamcity/work/e6c1f1c1b12e6dea/server

[19:31:25] [Step 2/6] Process exited with code 1

Mystery solved: we were using server-side checkout on this build job, which does not create a .git directory. Thus, SonarQube was (rightfully) confident that we weren’t actually running in a git repo.

What is the solution for this problem? How do I set the sonar runner to analyze the code that was checked out by TeamCity in a folder that does not has the the git folder?

1 Like

The solution is to use agent-side checkout.