SonarCloud/Travis - Main component does not belong to specified organization


I have an issue with trying to get SonarCloud and Travis correctly linked. It specifically gives the error “main component does not belong to specified organization”.
I am unsure what is meant by “main component”.
I did manage to get this working for my own SonarCloud account with my own fork of the same project, however, now I am trying to set this up for an organization of which I am a member rather than using my personal account. I made sure to give SonarCloud access to the repository on Github and I changed the organization name.

Has anyone encountered this problem before or have an idea how I can resolve it? I tried looking on the internet for a solution but I couldn’t find anyone with a similar issue.
The only thing that I noticed is that, when following the instructions to link SonarCloud with Travis, you are asked to create a user authentication token. Currently, the one I created is not for the SonarCloud organization but for my personal account. Would that be the issue?
Thanks in advance!

Where do you get this error?

Did you update the organization key in the Travis YML file?

I call sonar-scanner in the travis build. It first loads all kinds of stuff, then also seems to analyze files (as it says something like X/Y files analyzed, current file:…). It mentions some scanners that are loaded, that CPD is calculated for X files, and that an analysis report is generated. Then it gives the execution failure which says " ERROR: Error during SonarQube Scanner execution. ERROR: main component does not belong to specified organization".

As for the organization key, I think you mean the “organization” keyword in the travis.yml file under addons -> sonarcloud? If so then yes, I changed that to the organization’s name.

Could you give a bit more of the logs around the ERROR: Error during SonarQube Scanner execution. ERROR: main component does not belong to specified organization line. This is hard to know what happens.

Also, if you share the project keys (of the initial project which works on your own account and the other one on the new org), I could take a look more in details on what’s happening.

Thanks for your help, I figured out the problem. The project key was set to the project name, however this likely referred to my own (fork) of the project which was set up earlier on sonarcloud. It was resolved by changing the project key in the sonar properties file from projectName to organization_projectKey (which was the projectKey shown on the main page of this sonarcloud project).

1 Like