Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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}

like image 266
Ganesh Rao B Avatar asked Aug 16 '16 10:08

Ganesh Rao B


People also ask

Can we use environment variables in properties file?

You can put environment variables in your properties file, but Java will not automatically recognise them as environment variables and therefore will not resolve them. In order to do this you will have to parse the values and resolve any environment variables you find.

How do I use sonar project properties?

Go to your project folder which you want to scan. Create one new file inside your project's root folder path with name “sonar-project”. The extension of the file will be “. properties”.

What do you use environment variables for?

An environment variable is a dynamic "object" on a computer, containing an editable value, which may be used by one or more software programs in Windows. Environment variables help programs know what directory to install files in, where to store temporary files, and where to find user profile settings.

How do you give environment variables?

On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable.


2 Answers

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}
like image 69
Oleksandr Shmyrko Avatar answered Nov 15 '22 08:11

Oleksandr Shmyrko


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.

like image 25
diamond Avatar answered Nov 15 '22 07:11

diamond