Search code examples
.netsonarqubesonarscannersonar-scanner-cli

How do I configure dotnet SonarScanner to run parallel scans?


I'm trying to run two scans in parallel as part of a build process with the SonarScanner global tool (the dotnet tool) but I keep running into a concurrency problem where each instance of the scanner is clearly trying to read/write the same files located at /tmp/.sonarqube/....

Each thing being built build has been copied into a separate working directory (to try and avoid file conflicts) and I've tried setting SONAR_USER_HOME to be the root of those working directories. When I do that, it prints out the correct "User Cache" but the tmp directory (a cache I think?) still seems to be a shared location at /tmp/.sonarqube.

I've also tried setting /d:sonar.working.directory=/path/to/cwd but I get the error

"The property 'sonar.working.directory' is automatically set by the SonarScanner for MSBuild and cannot be overridden on the command line."

Is there some other way I can get this to play nice with parallel scans?


Solution

  • So the /tmp location was indeed the issue and the scanner tool uses the same location by default hence the file conflicts. As it turns out, it can be changed.

    Since each of my build jobs were running their own workspaces and in their own subprocess, I simply changed the TMPDIR environment variable within that subprocess to use a specific directory for that workspace. So for example:

    Parallel Job 1

    export TMPDIR=/tmp/job1/
    mkdir $TMPDIR
    # run scanner...
    

    Parallel Job 1

    export TMPDIR=/tmp/job2/
    mkdir $TMPDIR
    # run scanner...
    

    The scanner picked up these locations and used them as a tmp stash, and the file conflicts went away.