Can we ignore a folder in sonar.sources if it is not present during Sonarcloud analysis

We have a unique requirement. A repository consists of the following folder structure:

Branch A - A/*A.java
Branch B - B/B.java

We are using ‘Bitbucket pull request trigger’ module in Jenkins to trigger the Jenkins build and perform the Sonarcloud analysis for every PR created in Bitbucket.

As a part of this, in Jenkins under Analysis properties ( in Execute sonarQube scanner) , we have mentioned the sonar.host.url=https://sonarcloud.io and other necessary parameters along with sonar.sources=A/,B/

Now, if we make changes in Branch A and raise a pull request in bitbucket under A/A.java folder, the build is triggering automatically in Jenkins but it is failing since the folder-B is not present in Branch-A on sonar.sources we are landing with this error:

ERROR: The folder ‘B/’ does not exist for '***** (base directory = …)

If we remove the folder - B in Analysis properties ( in Execute sonarQube scanner) its works fine. But whenever we create a PR in folder B, the Jenkins job fails again saying that there is no Folder - B to perform the scan results.

So how to get rid of this error? Can we consider the folders which are in the specific branch during Sonarcloud scan and ignore the extra folders which are mentioned in the Sonar.sources?

Thank you,

Hello @Vishal3,

You can use a sonar-project.properties file to configure your analysis, see the documentation here. You can set sonar.sources=A/ on branch A and set sonar.sources=B/ on branch B since this file is checked into your version control system.

Hope that helps!

1 Like

Hi @TomVanBraband,

Thanks for the reply.

This solution went through my mind. But there are almost 20 branches in the repository and every branch and almost every branch has a different folder structure. So i think writing a separate step for all the different branches is not a effective solution.

Also, if we follow this process, whenever we create a branch from the stable branch, we have to edit the sonar-project.properties every time based on the new folder structure of the branch which is a hectic process.

Thank you,

Hi @Vishal3,

That’s too bad.

The only other thing I can think of is to use the sonar.exclusions property to exclude folders you don’t want be scanned, instead of using sonar.sources to specify the sources you do want be scanned. It will then automatically scan all folders in the project directory (so A/ on branch A and B/ on branch B).

That seems unusual. In all my experience, project branches all have the same basic structure. Especially Java projects, where strong conventions for code organization exist since the days of Maven. As a matter of fact, it’s not normal to configure sonar.sources by hand in Java projects, because the Maven or Gradle plugins take care of all that pain for you automatically.

Can you tell a bit more about your use case?

@TomVanBraband,

Either ways, we need some manual steps and efforts to do so and we cannot guarantee that it will work for all of the cases.

As a ops guy, i’m not sure what developers might commit and create, so covering all those use cases without manual invention is something i’m thinking of right now.

Anyways appreciate for your efforts in trying to find out the solution :slight_smile:

Cheers