Issue
I would like to load an external Groovy class (or classes) to use in my Groovy Postbuild action.
Resolution
Below is a simplified example of how to do this.
Create file /tmp/JenkinsPostBuild.groovy
with contents:
public class JenkinsPostBuild { def manager public JenkinsPostBuild(manager){ this.manager = manager } def run() { manager.listener.logger.println("I want to see this line in my job's output"); } }
In the job Post-build Actions - Groovy Postbuild:
Groovy Script::
import JenkinsPostBuild def postBuild = new JenkinsPostBuild(manager) postBuild.run()
Additional classpath:
JAR file path or URL: /tmp
That’s it!
Or if you wanted to call static methods:
Contents:
... static void runStatic(manager) { manager.listener.logger.println("I want to see this line in my job's output"); } ...
Groovy Script:
import JenkinsPostBuild JenkinsPostBuild.runStatic(manager)
See Groovy Postbuild Plugin for more.