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

StackOverflow https://stackoverflow.com/questions/20338181

  •  07-08-2022
  •  | 
  •  

Domanda

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

È stato utile?

Soluzione 2

Uncovered bug... Submitted to the user group: I believe there is a problem in sonar-ant-task-2.1->sonar-runner-2.4->sonar-runner-impl->Jars35

https://github.com/SonarSource/sonar-runner/blob/master/sonar-runner-impl/src/main/java/org/sonar/runner/impl/Jars35.java#L40

This line does not take into account the sonar.userHome property. When the ant-task runs the Jars35 invokes the FileCacheBuilder.build() without setting the userHome. Therefore, the builder chooses

https://github.com/SonarSource/sonar/blob/master/sonar-home/src/main/java/org/sonar/home/cache/FileCacheBuilder.java#L54

System.getProperty("user.home") + File.separator + ".sonar"

which, in my case is not a directory where the user has r/w access (/dev/null). Therefore the analysis fails with this error:

... Caused by: java.io.IOException: Unable to create directory /dev/null/.sonar/cache at org.apache.commons.io.FileUtils.forceMkdir(FileUtils.java:1748) at org.sonar.home.cache.FileCache.createDir(FileCache.java:155) ... 30 more

I think the Jars35 class needs to be able to set the userHome or this property will not have the intended affect. Even if the user has a valid home directory some cached jars will cache into the system user.home and the rest (after being loaded with the bootstrap implementation) will be loaded into the appropriate sonar.userHome location.

FileCacheProvider using the sonar.userHome setting to build the FileCache through the FileCacheBuilder. https://github.com/SonarSource/sonar/blob/master/sonar-batch/src/main/java/org/sonar/batch/bootstrap/FileCacheProvider.java#L34

I'll update with jira issue if entered

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top