SonarQube V9 environment variable not available in custom plugin

We are developing a custom language plugin

SonarQube docker version sonarqube:9.2.4-developer

The custom plugin loads fine and registers correctly. When running the SonarQube container we need to inject a variable to the plugin to configure to the local environment. The environment variable is available in the container (confirmed running bash on the container).

When calling System.getenv() the variable is not defined. I did find a similar problem with version 8 related to the security manager but this situation is slightly different in that the getenv() call succeeds but the environment variable is missing.

Summary: System.getenv() called in a custom plugin does not contain a defined container environment variable.

Environment variable was chosen for the convenience of defining when the container is run and not as the image it built.

Has anyone else experienced this behavior with V9?

Hi,

Welcome to the community!

To be clear, you’re looking for this value at analysis time? And when/whare are you setting it

 
HTH,
Ann

Ann,

Thanks for the follow up. Yes this environment variable is being accessed in a Sensor implementation.

Best
Graham

Hi Graham,

And you’re setting it on the analysis side in the build agent?

 
Ann

Ann,

Maybe my understanding on where this code runs is at fault. Is the call made from the sonar scanner or on the server?

So the scanner reads the plugin jar from the server to run the analysis?

I am setting the environment variable in the SonarQube server docker container. I am running the scanner as a docker container. So should I be setting the environment variable in the scanner container?

Graham

It appears that my understanding was incorrect. Setting the environment variable for the scanner solved the problem.

But this leads onto a different problem

How to transfer the configuration to the agent - would that be to define a property?

Graham

Hi Graham,

By “agent”… you mean the SonarQube server? Yes, I think you’re going to need to define a property. And at that point, it’s not clear to me that setting the value in the environment makes sense. Versus, for instance, setting it in the analysis command, E.G. sonar-scanner -Dsonar.grahamsValue=foo

Note that such values are transient - there for the duration of the analysis and then gone. Once you get into the realm of setting properties, then it’s time to explore where/how/how long. The discussion at the top of the Analysis Parameters page should be helpful.

 
HTH,
Ann

Ann,

I think I now have a path forward!! Thanks for all your help and quick replies.

Best
Graham