Package hudson.model

Class Environment

java.lang.Object
hudson.model.Environment
Direct Known Subclasses:
BuildWrapper.Environment

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.

Since:
1.286
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.

      Parameters:
      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.)

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

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