4

How can I find the path to a Jenkins plugin if I want to use it from a groovy script?

For example, just testing on the master, I'd like to be able to use the LabelParameterValue class from the NodeLabelParameter plugin. An example of what I'm looking for is below, (though it doesn't work).

currentParameters.add(new hudson.plugins.nodelabelparameter.LabelParameterValue(nodeName))

2
  • I was able to do what you are doing both from Jenkins Groovy console and Groovy system script running via Groovy Plugin. I used a class in Claim Plugin. So: (1) How are you running you Groovy script (2) Is the plugin loaded? Commented Jun 3, 2012 at 8:54
  • 1
    I discovered that this works in the Jenkins console, and it probably works in system scripts, but it doesn't work in the Groovy Postbuild (likely because it's not running on the master Jenkins). I guess the question now is how I can access the master via a Groovy Postbuild script. import org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterValue (taken from the package name on Github) Commented Jun 3, 2012 at 17:05

1 Answer 1

3

In Postbuild Groovy script you can specify Additional groovy classpath. For example: /var/jenkins/plugins/claim/WEB-INF/classes for Claim plugin code. I tried it and it worked.

Unfortunately the path has to be absolute and does not allow for environment variables (such as ${JENKINS_HOME}). Also, I am not entirely sure where the script will look when run on a slave - on the slave or on master.

Sign up to request clarification or add additional context in comments.

1 Comment

That worked great. Thanks! For anyone looking for this plugin specifically, it was in /var/lib/jenkins/plugins/nodelabelparameter/WEB-INF/classes, where /var/lib/jenkins/ should be replaced with your hardcoded Jenkins home. I should also mention that I found a workaround to this issue, which is to use an "Execute system Groovy script" build step. You can access the current build using: def thr = Thread.currentThread(); def build = thr?.executable and still import packages without classpath. (credit: bit.ly/K6G3OS)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.