Jenkins/Kubernetes/docker strips quotes

Have a very interesting problem here. Using Jenkins (2.150), SonarQube Scanner plugin (2.9), and running the Jenkins executors via Kubernetes plugin 1.15.2.

If you run the following job description you will notice that the quotes are stripped from the environment variable SONARQUBE_SCANNER_PARAMS which gives you an error:

    { :, sonar.login : ******} 
    SyntaxError: Unexpected token s in JSON at position 2

We are calling sonar with “npm run sonar”.

Job description to recreate:

node {
  container('jenkins-slave') {
      sh 'env'
        sh 'env'
        withDockerContainer(image: 'ubuntu') {
            sh 'env'

Notice that the 1st env doesn’t have the environment variable, the 2nd does (with quotes that would work), and the 3rd strips the quotes (like the example above). I’m expecting the following to work: { “” : “”, “sonar.login” : “******”}

Things I’ve done include trying to pass in the url and login but it appears that the login (an authentication token that works for other projects not running in docker) turns into the literal **** instead of just not showing it on the console output.

Command used when doing it that way:
env -u SONARQUBE_SCANNER_PARAMS npm run sonar --verbose --sonar.login=******

I think it does the literal of **** because I’ve tested calling: curl -v -u ******: doesn’t return anything after “withSonarQubeEnv” is called but works before.

Any thoughts on how to pass the environment variable with quotes? It seems like I can’t even re-export as the **** doesn’t let me export or print without it being obfuscated.

Thanks in advance for helping out.

Hi @Michael_Cole

I suspect that the withDockerContainer step does some additional processing of the environment variables before passing them on to the container. Looking at the Jenkins plugin we correctly set add the quotes to the generated JSON as you also noted, but have no control over how future steps handle the configuration.

So I’m not sure the SonarQube Scanner for Jenkins can even solve this issue.