adop-jenkins
adop-jenkins copied to clipboard
NodeJS not installing with 1.0 plugin
I was messing around with the latest from adop-docker-compose and noticed this error:
groovy.lang.MissingMethodException: No signature of method: static jenkins.plugins.nodejs.NodeJSPlugin.instance() is applicable for argument types: () values: [] Possible solutions: inspect(), isCase(java.lang.Object), save(), start(), start() at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1503) at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1489) at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at adop_nodejs$_run_closure1.doCall(adop_nodejs.groovy:27) at adop_nodejs$_run_closure1.doCall(adop_nodejs.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024) at groovy.lang.Closure.call(Closure.java:414) at groovy.lang.Closure.call(Closure.java:408) at groovy.lang.Closure.run(Closure.java:495) at java.lang.Thread.run(Thread.java:745)
I also couldn't see the default NodeJS installation either. The above suggests the plugin has changed and the adop_nodejs.groovy script needs updating perhaps.
I will add that I was installing all sorts and updated everything so my NodeJS plugin has ended up at version 1.0 - so this might be something we need to care about in the future when we upgrade, rather than right now.
@nickdgriffin @anton-kasperovich
There error in adop_nodejs.groovy line #27 is
def nodeJSPluginInstance = NodeJSPlugin.instance()
NodeJSPlugin has no instance method. I fixed it with the following.
def nodeJSPluginInstance = new NodeJSPlugin().getInstallations()
This is the sample script that I use to test this in Jenkins Script console.
import hudson.model.*;
import jenkins.model.*;
import hudson.tools.*;
import jenkins.plugins.nodejs.*;
import jenkins.plugins.nodejs.tools.*;
// Check if enabled
def env = System.getenv()
if (!env['ADOP_NODEJS_ENABLED'].toBoolean()) {
println "--> ADOP NodeJS Disabled"
return
}
// Variables
def nodejs_version = env['NODEJS_VERSION'] ?: '8.5.0'
def nodejs_global_packages = env['NODEJS_GLOBAL_PACKAGES']
def nodejs_packages_refresh_hours = env['NODEJS_PACKAGES_REFRESH_HOURS'].toLong()
println nodejs_version
println nodejs_global_packages
println nodejs_packages_refresh_hours
// Constants
def instance = Jenkins.getInstance()
// NodeJS
println "--> Configuring NodeJS"
def nodeJSPluginInstance = new NodeJSPlugin().getInstallations()
def nodejsInstaller = new NodeJSInstaller(nodejs_version,nodejs_global_packages,nodejs_packages_refresh_hours)
def installSourceProperty = new InstallSourceProperty([nodejsInstaller])
def nodejs_inst = new NodeJSInstallation(
"ADOP NodeJS", // Name
"", // Home
[installSourceProperty]
)
// Only add ADOP NodeJS if it does not exist - do not overwrite existing config
def nodejs_installations = nodeJSPluginInstance
def nodejs_inst_exists = false
nodejs_installations.each {
installation = (NodeJSInstallation) it
if ( nodejs_inst.getName() == installation.getName() ) {
nodejs_inst_exists = true
println("Found existing installation: " + installation.getName())
}
}
if (!nodejs_inst_exists) {
nodejs_installations += nodejs_inst
nodeJSPluginInstance.setInstallations((NodeJSInstallation[]) nodejs_installations)
nodeJSPluginInstance.save()
}
Should I create a Pull Request?