GitLab integration fails

Using GitLab we are getting scan fails for multiple merge requests

the command used is:

sonar-scanner -X -Dsonar.pullrequest.key=${CI_MERGE_REQUEST_IID} -Dsonar.pullrequest.base=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} -Dsonar.pullrequest.branch=${CI_COMMIT_REF_NAME}

and the docker image that is runnning the command is: sonarsource/sonar-scanner-cli:5.0.1

and inside the source code there is sonar-project.properties file that specify the sonar.projectKey and sonar.organization values

i am adding parts of the log of the failing task:

06:45:47.321 ERROR: Error during SonarScanner execution
[192](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L192)java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.InputComponentStore
[193](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L193) at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:52)
[194](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L194) at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
[195](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L195) at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
[196](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L196) at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
[197](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L197) at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
[198](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L198) at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
[199](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L199) at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
[200](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L200) at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
[201](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L201) at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
[202](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L202) at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
[203](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L203) at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
[204](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L204) at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
[205](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L205) at org.picocontainer.DefaultPicoContainer.instantiateComponentAsIsStartable(DefaultPicoContainer.java:1034)
[206](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L206) at org.picocontainer.DefaultPicoContainer.addAdapterIfStartable(DefaultPicoContainer.java:1026)
[207](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L207) at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1003)
[208](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L208) at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
[209](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L209) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:122)
[210](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L210) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
[211](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L211) at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)
[212](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L212) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
[213](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L213) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
[214](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L214) at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:57)
[215](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L215) at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:51)
[216](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L216) at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
[217](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L217) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[218](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L218) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[219](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L219) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[220](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L220) at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[221](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L221) at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
[222](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L222) at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
[223](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L223) at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
[224](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L224) at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
[225](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L225) at org.sonarsource.scanner.cli.Main.execute(Main.java:126)
[226](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L226) at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
[227](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L227) at org.sonarsource.scanner.cli.Main.main(Main.java:62)
[228](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L228)Caused by: java.lang.IllegalStateException: Unable to load component interface org.sonar.scanner.scan.branch.BranchConfiguration
[229](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L229) at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:52)
[230](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L230) at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
[231](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L231) at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
[232](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L232) at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
[233](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L233) at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
[234](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L234) at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
[235](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L235) at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
[236](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L236) at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
[237](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L237) at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
[238](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L238) at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
[239](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L239) at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
[240](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L240) at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
[241](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L241) at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
[242](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L242) at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
[243](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L243) at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:50)
[244](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L244) ... 34 more
[245](https://gitlab.com/cybellum/psa/-/jobs/5257893625#L245)Caused by: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator

Hi,

As you were probably already aware, here’s the root cause:

Where inside the source code is your sonar-project.properties file? It needs to be in the project root. Alternately, you can add those properties to the command line.

 
Ann

The file is located on the project root folder

also from the logs you can see that it loaded configuration from sonarcloud.io for the right project
and lastly - running the same sonar check job on a long lasting branch and not MR works smoothly

Hi,

Please post the full analysis log, redacted as necessary.

 
Thx,
Ann

this is the log as is

sonar.log (23.2 KB)

Hi,

Thanks for the log. Are you sure that SONAR_TOKEN is being set in the environment? I can see the project key in the log. I’m not seeing the organization key, though, so it should be double-checked too.

 
HTH,
Ann

I am sure - the SONAR_TOKEN is set an environment variable in gitlab - and is shared between all running of the pipeline
the error we get is for MR pipeline - and on top of that we have a similar daily run on the main branch that perform the SAME step with the same environment variable that is passing perfectly

besides from the log it is possible to see that this job managed to pull the configuration for the project from sonar - since it is not a public project - it needs a working token to do that

Hi,

I’m not sure I’ve seen a case of this error where the culprit wasn’t one of those three things (org, project, or token) being wrong or missing. But if you’d like to post your full analysis log, I’ll take another look.

 
Ann

how do i get a fuller log than what i sent you?

the current command being run is:
sonar-scanner -X -Dsonar.pullrequest.key=${CI_MERGE_REQUEST_IID} -Dsonar.pullrequest.base=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} -Dsonar.pullrequest.branch=${CI_COMMIT_REF_NAME}

anything else i need to add into it?

Hi,

That ought to be more than enough. Just give me the stdout logging starting from your analysis command.

 
Ann

and this is exactly what the attached file i gave before is - i already run it multiple time - the result are the same - if you want i can run it again

Hi,

:woman_facepalming:
Sorry. I forgot about that. I went back to the OP, which has only a log excerpt.

So… there’s no new log and there’s nothing new to find in it. In reviewing other threads with your problem, every one of them turned out to be a problem with SONAR_TOKEN.

 
:woman_shrugging:
Ann

i added echo commands before to double check that i actually have the token - i do, i created a new token and tried that one - still same result
i am adding the last log i have again - with the hope you will find something that i am missing
job.txt (20.7 KB)

Hi,

I’m not seeing anything. I would try regenerating your SONAR_TOKEN and also double-checking your GitLab access token (altho, as I said, this error usually means a problem with the Sonar token).

 
HTH,
Ann

the last log is using a new SONAR_TOKEN value
i am attaching another log where the same job pipeline succeeds the difference is that the succeeding job is run on a branch
while the failing job is running on a merge request

scheduled-job.txt (447.0 KB)

Hi @Lee_Elenbaas,

Could you send me your pipeline configuration for Gitlab? I would like to investigate and see if I can recreate the issue. Also if you can share any information about the type of project this is that could be helpful, I see that there is python and typescript from the logs.

It is interesting that you are only seeing these errors on the short-lived branches, I will see if I can identify a cause of the issue.

our job definition that is used for both scenarios is:

sonar-check:
  stage: sonar-check
  image:
    name: sonarsource/sonar-scanner-cli:5.0.1
    entrypoint: [""]
  tags: !reference [.global_tags, tags]
  retry: !reference [.global_retry, retry]
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script:
    - 'echo "sonar-values:"'
    - 'echo "  sonar.token: ${SONAR_TOKEN}"'
    - 'echo "  sonar.host.url: ${SONAR_HOST_URL}"'
    - sonar-scanner -X -Dsonar.pullrequest.key=${CI_MERGE_REQUEST_IID} -Dsonar.pullrequest.base=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} -Dsonar.pullrequest.branch=${CI_COMMIT_REF_NAME}
  needs:
    - job: sonar-prepare
  rules:
    - if: $Flow=="sonar_check"
      when: always
      allow_failure: true
    - if: $Flow=="deploy_cluster"
      when: always
      allow_failure: true
    - if: $Flow=="skip_gitlab_env"
      when: always
      allow_failure: true
    - if: $Flow=="MR" && $CI_MERGE_REQUEST_TARGET_BRANCH_PROTECTED != "true"
      when: always
      allow_failure: true
    - if: $Flow=="MR" && $CI_MERGE_REQUEST_TARGET_BRANCH_PROTECTED == "true"
      when: always
      allow_failure: false

note that i do not think that gitlab is performing in on a short lived branch - i think that they run it on a detached commit

Hi @Lee_Elenbaas ,

Sorry for the delay, just an update for you. I have been attempting to recreate the issue you are experiencing. At one point I was successfully seeing an issue with the same output you had described.

The issue I was experiencing came from my SONAR_TOKEN being in a Protected state in the CI/CD variables. It might be worth checking that this is not the case in your current setup.

1 Like

job-unmasked.txt (20.6 KB)
when i am removing the masked flag from the SONAR_TOKEN environment variable i am getting this log (i remasked the token manualy)

the behavior is still the same
the variable was never protected - it was only masked

any other direction i can try?

Interesting, ok, whilst testing on my side I was also checking to see if the other keys were being set correctly. Could you output the other keys you are passing?

For example if I run the build you have specified on my master branch I get the following results:

$ echo "sonar-values:"
sonar-values:
$ echo "  sonar.token: ${SONAR_TOKEN}"
  sonar.token: xxxxxxxxxxxxxxxxxxxxxx
$ echo "  sonar.host.url: ${SONAR_HOST_URL}"
  sonar.host.url: https://sonarcloud.io
$ echo "  sonar.pullrequest.key: ${CI_MERGE_REQUEST_IID}"
  sonar.pullrequest.key: 3
$ echo "  sonar.pullrequest.base: ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
  sonar.pullrequest.base: main
$ echo "  sonar.pullrequest.branch: ${CI_COMMIT_REF_NAME}"
  sonar.pullrequest.branch: branch-new-2
$ sonar-scanner -X -Dsonar.pullrequest.key=${CI_MERGE_REQUEST_IID} -Dsonar.pullrequest.base=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} -Dsonar.pullrequest.branch=${CI_COMMIT_REF_NAME}

It could be good to clarify exactly what values you are seeing here, I ask as if I pass these values incorrectly I see the same error you have mentioned.

You have said that you have different configurations for the branches vs. the merge requests. Would you also be able to share some information about this?

Finally, I see that you are missing blame information. Incase you were wanting this I believe the following would resolve that, however I don’t believe it is related:

variables:
  SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
  GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task

sonarcloud-check:
  image:
    name: sonarsource/sonar-scanner-cli:5.0.1