public abstract class Environment extends Object
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.
BuildWrapper
,
NodeProperty
,
RunListener.setUpEnvironment(AbstractBuild, Launcher, BuildListener)
Constructor and Description |
---|
Environment() |
Modifier and Type | Method and Description |
---|---|
void |
buildEnvVars(Map<String,String> env)
Adds environmental variables for the builds to the given map.
|
static Environment |
create(EnvVars envVars)
Creates
Environment implementation that just sets the variables as given in the parameter. |
boolean |
tearDown(AbstractBuild build,
BuildListener listener)
Runs after the
Builder completes, and performs a tear down. |
public void buildEnvVars(Map<String,String> env)
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.public boolean tearDown(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException
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.IOException
- terminates the build abnormally. Jenkins will handle the
exception and reports a nice error message.InterruptedException
public static Environment create(EnvVars envVars)
Environment
implementation that just sets the variables as given in the parameter.Copyright © 2004–2022. All rights reserved.