use of hudson.tasks.BuildWrapper in project hudson-2.x by hudson.
the class AbstractBuild method getSensitiveBuildVariables.
/**
* Builds up a set of variable names that contain sensitive values that
* should not be exposed. The expection is that this set is populated with
* keys returned by {@link #getBuildVariables()} that should have their
* values masked for display purposes.
*
* @since 1.378
*/
public Set<String> getSensitiveBuildVariables() {
Set<String> s = new HashSet<String>();
ParametersAction parameters = getAction(ParametersAction.class);
if (parameters != null) {
for (ParameterValue p : parameters) {
if (p.isSensitive()) {
s.add(p.getName());
}
}
}
// Allow BuildWrappers to determine if any of their data is sensitive
if (project instanceof BuildableItemWithBuildWrappers) {
for (BuildWrapper bw : ((BuildableItemWithBuildWrappers) project).getBuildWrappersList()) {
bw.makeSensitiveBuildVariables(this, s);
}
}
return s;
}
use of hudson.tasks.BuildWrapper in project hudson-2.x by hudson.
the class Run method run.
protected final void run(Runner job) {
if (result != null)
// already built.
return;
StreamBuildListener listener = null;
runner = job;
onStartBuilding();
try {
// to set the state to COMPLETE in the end, even if the thread dies abnormally.
// otherwise the queue state becomes inconsistent
long start = System.currentTimeMillis();
try {
try {
Charset charset = Computer.currentComputer().getDefaultCharset();
this.charset = charset.name();
// don't do buffering so that what's written to the listener
// gets reflected to the file immediately, which can then be
// served to the browser immediately
OutputStream logger = new FileOutputStream(getLogFile());
RunT build = job.getBuild();
// Global log filters
for (ConsoleLogFilter filter : ConsoleLogFilter.all()) {
logger = filter.decorateLogger((AbstractBuild) build, logger);
}
// Project specific log filterss
if (project instanceof BuildableItemWithBuildWrappers && build instanceof AbstractBuild) {
BuildableItemWithBuildWrappers biwbw = (BuildableItemWithBuildWrappers) project;
for (BuildWrapper bw : biwbw.getBuildWrappersList()) {
logger = bw.decorateLogger((AbstractBuild) build, logger);
}
}
listener = new StreamBuildListener(logger, charset);
listener.started(getCauses());
RunListener.fireStarted(this, listener);
// create a symlink from build number to ID.
Util.createSymlink(getParent().getBuildDir(), getId(), String.valueOf(getNumber()), listener);
setResult(job.run(listener));
LOGGER.info(toString() + " main build action completed: " + result);
CheckPoint.MAIN_COMPLETED.report();
} catch (ThreadDeath t) {
throw t;
} catch (AbortException e) {
// orderly abortion.
result = Result.FAILURE;
listener.error(e.getMessage());
LOGGER.log(FINE, "Build " + this + " aborted", e);
} catch (RunnerAbortedException e) {
// orderly abortion.
result = Result.FAILURE;
LOGGER.log(FINE, "Build " + this + " aborted", e);
} catch (InterruptedException e) {
// aborted
result = Result.ABORTED;
listener.getLogger().println(Messages.Run_BuildAborted());
LOGGER.log(Level.INFO, toString() + " aborted", e);
} catch (Throwable e) {
handleFatalBuildProblem(listener, e);
result = Result.FAILURE;
}
// even if the main build fails fatally, try to run post build processing
job.post(listener);
} catch (ThreadDeath t) {
throw t;
} catch (Throwable e) {
handleFatalBuildProblem(listener, e);
result = Result.FAILURE;
} finally {
long end = System.currentTimeMillis();
// @see HUDSON-5844
duration = Math.max(end - start, 0);
// advance the state.
// the significance of doing this is that Hudson
// will now see this build as completed.
// things like triggering other builds requires this as pre-condition.
// see issue #980.
state = State.POST_PRODUCTION;
try {
job.cleanUp(listener);
} catch (Exception e) {
handleFatalBuildProblem(listener, e);
// too late to update the result now
}
RunListener.fireCompleted(this, listener);
if (listener != null)
listener.finished(result);
if (listener != null)
listener.closeQuietly();
try {
save();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to save build record", e);
}
}
try {
getParent().logRotate();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to rotate log", e);
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Failed to rotate log", e);
}
} finally {
onEndBuilding();
}
}
use of hudson.tasks.BuildWrapper in project hudson-2.x by hudson.
the class AbstractBuild method getBuildVariables.
/**
* Provides additional variables and their values to {@link Builder}s.
*
* <p>
* This mechanism is used by {@link MatrixConfiguration} to pass
* the configuration values to the current build. It is up to
* {@link Builder}s to decide whether it wants to recognize the values
* or how to use them.
*
* <p>
* This also includes build parameters if a build is parameterized.
*
* @return
* The returned map is mutable so that subtypes can put more values.
*/
public Map<String, String> getBuildVariables() {
Map<String, String> r = new HashMap<String, String>();
ParametersAction parameters = getAction(ParametersAction.class);
if (parameters != null) {
// this is a rather round about way of doing this...
for (ParameterValue p : parameters) {
String v = p.createVariableResolver(this).resolve(p.getName());
if (v != null)
r.put(p.getName(), v);
}
}
customizeBuildVariables(r);
// allow the BuildWrappers to contribute additional build variables
if (project instanceof BuildableItemWithBuildWrappers) {
for (BuildWrapper bw : ((BuildableItemWithBuildWrappers) project).getBuildWrappersList()) bw.makeBuildVariables(this, r);
}
return r;
}
use of hudson.tasks.BuildWrapper in project hudson-2.x by hudson.
the class FileParameterValue method createBuildWrapper.
@Override
public BuildWrapper createBuildWrapper(AbstractBuild<?, ?> build) {
return new BuildWrapper() {
@Override
public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
if (!StringUtils.isEmpty(file.getName())) {
listener.getLogger().println("Copying file to " + location);
FilePath locationFilePath = build.getWorkspace().child(location);
locationFilePath.getParent().mkdirs();
locationFilePath.copyFrom(file);
file = null;
locationFilePath.copyTo(new FilePath(getLocationUnderBuild(build)));
}
return new Environment() {
};
}
};
}
Aggregations