Groovy script fails to resolve class com.cloudbees.hudson.plugins.modeling.Model

Article ID:360030103852
1 minute readKnowledge base

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

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.*