Is it possible to use environment variable in sonar-project.properties file

You cannot pass env variable into sonar-project.property file.

  • If you are creating sonar-project.property file from jenkins, you can use build with param.

    (or)

  • Create a sonar-project.properties without sonar.source.

  • Create build with param variable {path}, get the src path from user for each build,

  • Map the variable with sonar.source=${path} in sh.

  • Append sonar.source to sonar-project.properties for each build in sh using (>>) or cmd from jenkins.

    eg) sonar.source="path" >> sonar-project.properties

finally work space contains sonar-project.properties file with src path.


Environment variables are supported in sonar-project.properties starting from SonarQube Scanner version 2.9 (see SQSCANNER-9).

So, this should work now:

sonar.sources=${env.SONAR_RUN_WORKSPACE}