Issue
-
Previously working groovy scripts started to fail after upgrading your Jenkins instance
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 1: unable to resolve class com.cloudbees.hudson.plugins.modeling.Model
Environment
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Operations Center
-
CloudBees CI (CloudBees Core) on traditional platforms - Client controller
-
CloudBees CI (CloudBees Core) on traditional platforms - Operations Center
-
CloudBees Jenkins Enterprise - Managed controller
Description
You may notice that a simple groovy script that was successfully running on Jenkins instances including version 2.138.4.3-rolling
import com.cloudbees.hudson.plugins.modeling.Model print "Done"
started to fail when you upgraded to Jenkins version 2.164.1.2-rolling
or later. The exact error reads
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 1: unable to resolve class com.cloudbees.hudson.plugins.modeling.Model @ line 1, column 1. import com.cloudbees.hudson.plugins.modeling.Model ^ 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)
Resolution
Using a wildcard with Java import statement resolves the error
import com.cloudbees.hudson.plugins.modeling.*
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.