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;
[...]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With