Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groovy hook tries to compile init scripts #226

Open
alexsedova opened this issue Apr 30, 2018 · 1 comment
Open

Groovy hook tries to compile init scripts #226

alexsedova opened this issue Apr 30, 2018 · 1 comment

Comments

@alexsedova
Copy link
Contributor

alexsedova commented Apr 30, 2018

Jenkins as a code setup has good numbers of groovy scripts for many different plugins configurations. However, we don't want users to install all plugins the setup is supporting. One of the option to prevent compilation during Jenkins startup is to use a def dynamic variable and whole classpath. It seems some scripts don't meet these requirements and fail during startup with a compilation error. For example, artifactory.groovy.

WARNING: Failed to run script file:/var/jenkins_home/init.groovy.d/artifactory.groovy
�[35mjmaster_1       |�[0m org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
�[35mjmaster_1       |�[0m /var/jenkins_home/init.groovy.d/artifactory.groovy: 22: unable to resolve class CredentialsConfig 
�[35mjmaster_1       |�[0m  @ line 22, column 23.
�[35mjmaster_1       |�[0m        CredentialsConfig deployerCredentials = new CredentialsConfig(getPasswordCredentials(serverConfig.deployerCredentialsId),
�[35mjmaster_1       |�[0m                          ^
�[35mjmaster_1       |�[0m 
�[35mjmaster_1       |�[0m /var/jenkins_home/init.groovy.d/artifactory.groovy: 22: unable to resolve class CredentialsConfig 
�[35mjmaster_1       |�[0m  @ line 22, column 45.
�[35mjmaster_1       |�[0m    sConfig deployerCredentials = new Creden
�[35mjmaster_1       |�[0m                                  ^
�[35mjmaster_1       |�[0m 
�[35mjmaster_1       |�[0m /var/jenkins_home/init.groovy.d/artifactory.groovy: 25: unable to resolve class CredentialsConfig 
�[35mjmaster_1       |�[0m  @ line 25, column 23.
�[35mjmaster_1       |�[0m        CredentialsConfig resolverCredentials = new CredentialsConfig(getPasswordCredentials(serverConfig.deployerCredentialsId),
�[35mjmaster_1       |�[0m                          ^
�[35mjmaster_1       |�[0m 
�[35mjmaster_1       |�[0m /var/jenkins_home/init.groovy.d/artifactory.groovy: 25: unable to resolve class CredentialsConfig 
�[35mjmaster_1       |�[0m  @ line 25, column 45.
�[35mjmaster_1       |�[0m    sConfig resolverCredentials = new Creden
�[35mjmaster_1       |�[0m                                  ^
�[35mjmaster_1       |�[0m 
�[35mjmaster_1       |�[0m /var/jenkins_home/init.groovy.d/artifactory.groovy: 28: unable to resolve class ArtifactoryServer 
�[35mjmaster_1       |�[0m  @ line 28, column 10.
�[35mjmaster_1       |�[0m        List<ArtifactoryServer> servers =  desc.getArtifactoryServers()
�[35mjmaster_1       |�[0m             ^
�[35mjmaster_1       |�[0m 
�[35mjmaster_1       |�[0m /var/jenkins_home/init.groovy.d/artifactory.groovy: 29: unable to resolve class ArtifactoryServer 
�[35mjmaster_1       |�[0m  @ line 29, column 23.
�[35mjmaster_1       |�[0m        ArtifactoryServer server = new ArtifactoryServer(serverConfig.serverName,
�[35mjmaster_1       |�[0m                          ^
�[35mjmaster_1       |�[0m 
�[35mjmaster_1       |�[0m /var/jenkins_home/init.groovy.d/artifactory.groovy: 29: unable to resolve class ArtifactoryServer 
�[35mjmaster_1       |�[0m  @ line 29, column 32.
�[35mjmaster_1       |�[0m        ArtifactoryServer server = new ArtifactoryServer(serverConfig.serverName,
�[35mjmaster_1       |�[0m                                   ^
�[35mjmaster_1       |�[0m 
�[35mjmaster_1       |�[0m 7 errors
�[35mjmaster_1       |�[0m 
�[35mjmaster_1       |�[0m 	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
�[35mjmaster_1       |�[0m 	at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:946)
�[35mjmaster_1       |�[0m 	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593)
�[35mjmaster_1       |�[0m 	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:542)
�[35mjmaster_1       |�[0m 	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
�[35mjmaster_1       |�[0m 	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
�[35mjmaster_1       |�[0m 	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
�[35mjmaster_1       |�[0m 	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
�[35mjmaster_1       |�[0m 	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:584)
�[35mjmaster_1       |�[0m 	at jenkins.util.groovy.GroovyHookScript.execute(GroovyHookScript.java:136)
�[35mjmaster_1       |�[0m 	at jenkins.util.groovy.GroovyHookScript.execute(GroovyHookScript.java:127)
�[35mjmaster_1       |�[0m 	at jenkins.util.groovy.GroovyHookScript.run(GroovyHookScript.java:110)
�[35mjmaster_1       |�[0m 	at hudson.init.impl.GroovyInitScript.init(GroovyInitScript.java:41)
�[35mjmaster_1       |�[0m 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
�[35mjmaster_1       |�[0m 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
�[35mjmaster_1       |�[0m 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
�[35mjmaster_1       |�[0m 	at java.lang.reflect.Method.invoke(Method.java:498)
�[35mjmaster_1       |�[0m 	at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:104)
�[35mjmaster_1       |�[0m 	at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:175)
�[35mjmaster_1       |�[0m 	at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:282)
�[35mjmaster_1       |�[0m 	at jenkins.model.Jenkins$7.runTask(Jenkins.java:1089)
�[35mjmaster_1       |�[0m 	at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:210)
�[35mjmaster_1       |�[0m 	at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
�[35mjmaster_1       |�[0m 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
�[35mjmaster_1       |�[0m 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
�[35mjmaster_1       |�[0m 	at java.lang.Thread.run(Thread.java:745)
@alexsedova
Copy link
Contributor Author

alexsedova commented Apr 30, 2018

Found two scripts bitbucket. groovy and artifactory.groovy. The problem is it tries to download classes by name not by classpath. To avoid that it needs to create a special object using Class.forName(String: "whole-package-class-path") and call this class constructor using getDeclaredConstructor() default method.

alexsedova pushed a commit that referenced this issue Apr 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant