package hudson.tasks; import hudson.ExtensionPoint; import hudson.Launcher; import hudson.model.Build; import hudson.model.BuildListener; import hudson.model.Describable; import hudson.model.Project; import java.util.Map; import java.io.IOException; /** * Pluggability point for performing pre/post actions for the build process. * *

* STILL EXPERIMENTAL. SUBJECT TO CHANGE * *

* This extension point enables a plugin to set up / tear down additional * services needed to perform a build, such as setting up local X display, * or launching and stopping application servers for testing. * *

* An instance of {@link BuildWrapper} is associated with a {@link Project} * with configuration information as its state. An instance is persisted * along with {@link Project}. * *

* The {@link #setUp(Build,Launcher,BuildListener)} method is invoked for each build. * * @author Kohsuke Kawaguchi */ public abstract class BuildWrapper implements ExtensionPoint, Describable { /** * Represents the environment set up by {@link BuildWrapper#setUp(Build,Launcher,BuildListener)}. * *

* It is expected that the subclasses of {@link BuildWrapper} extends this * class and implements its own semantics. */ public abstract class Environment { /** * Adds environmental variables for the builds to the given map. * *

* If the {@link Environment} object wants to pass in information * to the build that runs, it can do so by exporting additional * environment variables to the map. * *

* When this method is invoked, the map already contains the * current "planned export" list. * * @param env * never null. */ public void buildEnvVars(Map env) { // no-op by default } /** * Runs after the {@link Builder} completes, and performs a tear down. * *

* This method is invoked even when the build failed, so that the * clean up operation can be performed regardless of the build result * (for example, you'll want to stop application server even if a build * fails.) * * @param build * The same {@link Build} object given to the set up method. * @param listener * The same {@link BuildListener} object given to the set up method. * @return * true if the build can continue, false if there was an error * and the build needs to be aborted. * @throws IOException * terminates the build abnormally. Hudson will handle the exception * and reports a nice error message. */ public abstract boolean tearDown( Build build, BuildListener listener ) throws IOException; } /** * Runs before the {@link Builder} runs, and performs a set up. * * @param build * The build in progress for which an {@link Environment} object is created. * Never null. * @param launcher * This launcher can be used to launch processes for this build. * If the build runs remotely, launcher will also run a job on that remote machine. * Never null. * @param listener * Can be used to send any message. * @return * non-null if the build can continue, null if there was an error * and the build needs to be aborted. * @throws IOException * terminates the build abnormally. Hudson will handle the exception * and reports a nice error message. */ public abstract Environment setUp( Build build, Launcher launcher, BuildListener listener ) throws IOException; }