How can I run sonar analysis with a user with no home directory: unable to create user /dev/null/.sonar/cache

green reign picture green reign · Dec 2, 2013 · Viewed 12.2k times · Source

I have sonarqube server 4.0 and sonar-ant-task-2.1. My sonar target runs fine on my local RHEL 5 machine but as soon as I promote it to a shared RHEL 5 environment it will be run by a user whose home directory is "/dev/null" apparently. I can't change that.

I get the following error: Unable to create user cache/dev/null/.sonar/cache Caused by: java.io.IOException: Unable to create directory /dev/null/.sonar/cache

I set the following two properties:

<property name="sonar.working.directory" value="dirWhereUserHasAccess"/> <property name="sonar.userHome" value="dirWhereUserHasAccess"/>

These properties seem to have the desired affect locally however when run on the shared environment the sonar.userHome is not used. I get the same error. It's trying to use /dev/null.

How can I get sonar to stop trying to access /dev/null for this cache?

Bug description is below. Jira task created https://jira.codehaus.org/browse/SONARPLUGINS-3349

Answer

kevinarpe picture kevinarpe · Feb 28, 2015

The default Sonar cache directory path is: System.getProperty("user.home") + File.separator + ".sonar"

Set environment variable SONAR_USER_HOME before running mvn sonar:sonar.

Example for Bash: SONAR_USER_HOME=/my/path/.sonar mvn sonar:sonar

Unfortunately, the name SONAR_USER_HOME is misleading -- it is not a replacement for user.home; it is the complete cache directory path. To replicate default behavior, the following would suffice in Bash: SONAR_USER_HOME=$HOME/.sonar mvn sonar:sonar

Ref: https://github.com/SonarSource/sonarqube/blob/1f231f2cfcd47e66ca818cd1a8cbd93cc89af45d/sonar-home/src/main/java/org/sonar/home/cache/FileCacheBuilder.java