Search code examples
jenkinssonarqubesonar-runnersonarqube-scan

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


I am executing sonar through Jenkins build, there is use-case where 'src' location changes depending upon build so i want to use environment variable for specifying 'src' path.

For example in sonar-project.properties i want to specify as shown below:

src= c:/project/workspace instead i want to use src =${SONAR_RUN_WORKSPACE}


Solution

  • 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.