Using cli: false to expand environment variables in withSonarQubeEnv

We’ve just updated to the Sonar 2.12 Jenkins plugin release, hoping to use the new cli: false syntax. Unfortunately, using the example as-is:

withSonarQubeEnv(‘SonarQube’, cli: false) {
}

I receive the error:

java.lang.IllegalArgumentException: Expected named arguments but got [{cli=false}, SonarQube]

If I try naming the first argument:

withSonarQubeEnv(‘SonarQube’, cli: false) {
}

I receive the error:

org.kohsuke.stapler.NoStaplerConstructorException: There’s no @DataBoundConstructor on any constructor of class java.lang.String

Caused: java.lang.IllegalArgumentException: Could not instantiate {installationName={installationName=SonarQube, cli=false}} for hudson.plugins.sonar.SonarBuildWrapper

which looks funky, as it’s trying to bundle up the cli argument and pass it to the constructor parameter.

This is odd, as the Jenkins pipeline documentation explicitly suggests combining DataBoundConstructor and DataBoundSetter:

Is there a recommended way to pass both? Does the example in the SonarQube documentation need updating?

Any update on this? I’ve also tried with envOnly: true as per:

but the errors are similar. Omitting the name of the installationName argument gives:

java.lang.IllegalArgumentException: Expected named arguments but got [{envOnly=true}, SonarQube]

including it yields:

org.kohsuke.stapler.NoStaplerConstructorException: There's no @DataBoundConstructor on any constructor of class java.lang.String
	at org.kohsuke.stapler.ClassDescriptor.loadConstructorParamNames(ClassDescriptor.java:265)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.<init>(DescribableModel.java:153)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:474)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:409)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:329)
Caused: java.lang.IllegalArgumentException: Could not instantiate {installationName={installationName=SonarQube, envOnly=true}} for hudson.plugins.sonar.SonarBuildWrapper

Bump (again). I thought I’d try this with the older syntax:

import hudson.plugins.sonar.SonarBuildWrapper

wrap([ $class: 'SonarBuildWrapper', installationName: 'SonarQube', envOnly: true ]) {
}

and I receive the less cryptic:

WARNING: Unknown parameter(s) found for class type 'hudson.plugins.sonar.SonarBuildWrapper': envOnly

what state is this BuildWrapper in, and in what plugin versions is it available?

Hi all,

The parameter cli was renamed too envOnly.
If you previously had cli: false in your pipeline, then you should change this to envOnly: true

Cheers,
Mark

Thanks Mark.

As you can see from the post above, I’ve tried envOnly: true too, and am still getting errors indicating envOnly is not defined. We’ve upgraded the Sonar plugin to 2.12, should we be using a different version?

Hi @JackWhelpton

No the rename of the parameter was released in version 2.12 of the plugin so you should be good if the plugin version you have installed is 2.12.

Maybe a reboot of Jenkins (or its nodes) is needed to pickup the change.

Cheers,
Mark