简体   繁体   中英

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}

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}

Nope, environment variables are not supported in sonar-project.properties . In any case, back to your use-case: you better use a relative path for sonar.sources so that, wherever analysis is ran (ie whatever workspace with Jenkins), sources are always found at the expected place (from the project's base directory).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM