Package hudson.model

Class Environment

Direct Known Subclasses:

public abstract class Environment extends Object
Represents some resources that are set up for the duration of a build to be torn down when the build is over.

This is often used to run a parallel server necessary during a build, such as an application server, a database reserved for the build, X server for performing UI tests, etc.

By having a plugin that does this, instead of asking each build script to do this, we can simplify the build script. Environment abstraction also gives you guaranteed "tear down" phase, so that such resource won't keep running forever.

See Also:
  • Constructor Details

    • Environment

      public Environment()
  • Method Details

    • buildEnvVars

      public void buildEnvVars(Map<String,String> env)
      Adds environmental variables for the builds to the given map.

      If the 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.

      env - never null. This really should have been typed as EnvVars but by the time we realized it it was too late.
    • tearDown

      public boolean tearDown(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException
      Runs after the 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.)

      build - The same Build object given to the set up method.
      listener - The same BuildListener object given to the set up method.
      true if the build can continue, false if there was an error and the build needs to be failed.
      IOException - terminates the build abnormally. Jenkins will handle the exception and reports a nice error message.
    • create

      public static Environment create(EnvVars envVars)
      Creates Environment implementation that just sets the variables as given in the parameter.