Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Packages on Groovy Classpath?

When using the Groovy Jenkins plugin (not the Groovy Post Build Plugin, which is a different thing) as a Post Step, I can't resolve classes in the hudson.model package.

Do I need to add the Jenkins .war onto the classpath, or should these packages already be there?

Script:

import hudson.model.*;
import hudson.util.*;

AbstractBuild currentBuild = (AbstractBuild) Thread.currentThread().executable;
def mavenVer = currentBuild.getMavenArtifacts().getModuleRecords()[0].mainArtifact.version;
println mavenVer;
ParametersAction newParamAction = new hudson.model.ParametersAction(new hudson.model.StringParameterValue(“MAVEN_VERSION”, mavenVer));
currentBuild.addAction(newParamAction);

Output:

[Common] $ /home/tester/tools/Groovy_1.8.3/bin/groovy /home/tester/workspace/Common/hudson8369102960709507246.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/home/tester/workspace/Common/hudson8369102960709507246.groovy: 8: unable to resolve class AbstractBuild 
 @ line 8, column 15.
   AbstractBuild currentBuild = (AbstractBuild) Thread.currentThread().executable;
[...]
like image 592
EngineerBetter_DJ Avatar asked Apr 03 '12 15:04

EngineerBetter_DJ


1 Answers

Yes, if it's a Groovy Script you do need to add the jenkins-core jar to your classpath, and the stapler jar too.

If it's a Groovy System Script then it is run inside the master's JVM, meaning all the Jenkins classes and dependencies are already on the classpath.

like image 151
EngineerBetter_DJ Avatar answered Sep 19 '22 08:09

EngineerBetter_DJ