Open michaelsauter opened 4 years ago
In testing, we discovered that 2.11 does not work with the code in /var/lib/jenkins/init.groovy.d/sonarqube.groovy
. The script shows the following error on boot:
/var/lib/jenkins/init.groovy.d/sonarqube.groovy: 4: unable to resolve class hudson.plugins.sonar.utils.SQServerVersions
--
| @ line 4, column 1.
| import hudson.plugins.sonar.utils.SQServerVersions
| ^
|
| 1 error
|
| at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
| at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:958)
| at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
| at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:554)
| at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
| at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
| at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
| at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
| at groovy.lang.GroovyShell.evaluate(GroovyShell.java:584)
| at jenkins.util.groovy.GroovyHookScript.execute(GroovyHookScript.java:136)
| at jenkins.util.groovy.GroovyHookScript.execute(GroovyHookScript.java:127)
| at jenkins.util.groovy.GroovyHookScript.run(GroovyHookScript.java:110)
| at hudson.init.impl.GroovyInitScript.init(GroovyInitScript.java:41)
| at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
| at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| at java.base/java.lang.reflect.Method.invoke(Method.java:566)
| at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:104)
| at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:175)
| at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
| at jenkins.model.Jenkins$5.runTask(Jenkins.java:1133)
| at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
| at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
| at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
| at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
| at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
| at java.base/java.lang.Thread.run(Thread.java:834)
Given the error above, we need to also fix #411 to force everyone to move to 2.11. Otherwise we have users on 2.6.1 and users on 2.11, but in /var/lib/jenkins/init.groovy.d/sonarqube.groovy
we can only support one version as they are incompatible. If we have a way to force everyone to move to 2.11, we can also fix the code to use the new API.
Now that #411 is fixed, it is possible to address this. I changed the sonarqube.groovy
file to this:
import jenkins.model.Jenkins
import hudson.plugins.sonar.SonarInstallation
import hudson.plugins.sonar.model.TriggersConfig
def jen = Jenkins.getInstance()
def env = System.getenv()
// https://github.com/SonarSource/sonar-scanner-jenkins/blob/sonar-2.11/src/main/java/hudson/plugins/sonar/SonarGlobalConfiguration.java
def conf = jen.getDescriptor("hudson.plugins.sonar.SonarGlobalConfiguration")
// https://github.com/SonarSource/sonar-scanner-jenkins/blob/sonar-2.11/src/main/java/hudson/plugins/sonar/SonarInstallation.java#L72-L83
def inst = new SonarInstallation(
"SonarServerConfig", // name
env['SONAR_SERVER_URL'], // serverUrl
env['SONAR_SERVER_AUTH_TOKEN'], // serverAuthenticationToken
"", // mojoVersion
"", // additionalProperties
new TriggersConfig(), // triggers
"" // additionalAnalysisProperties
)
conf.setInstallations(inst)
conf.save()
That avoids the error. However, the credential migration does not seem to work properly. On the first run, a credential is created, but the config does not point to it. The result is that the auth token is null
. Once the created credential is registered (manually) in the config, it works.
So further investigation is needed ...
Moving this to v4. The best solution is probably to migrate the token ourselves to a secret that is synced with Jenkins.
We use 2.6.1, 2.11 is the newest.