use of hudson.AbortException in project workflow-job-plugin by jenkinsci.
the class WorkflowRun method finish.
/**
* Handles normal build completion (including errors) but also handles the case that the flow did not even start correctly, for example due to an error in {@link FlowExecution#start}.
*/
private void finish(@Nonnull Result r, @CheckForNull Throwable t) {
setResult(r);
duration = Math.max(0, System.currentTimeMillis() - getStartTimeInMillis());
LOGGER.log(Level.INFO, "{0} completed: {1}", new Object[] { toString(), getResult() });
if (listener == null) {
LOGGER.log(Level.WARNING, this + " failed to start", t);
} else {
RunListener.fireCompleted(WorkflowRun.this, listener);
if (t instanceof AbortException) {
listener.error(t.getMessage());
} else if (t instanceof FlowInterruptedException) {
((FlowInterruptedException) t).handle(this, listener);
} else if (t != null) {
// TODO 2.43+ use Functions.printStackTrace
listener.getLogger().println(Functions.printThrowable(t).trim());
}
listener.finished(getResult());
listener.closeQuietly();
}
logsToCopy = null;
try {
save();
} catch (Exception x) {
LOGGER.log(Level.WARNING, "failed to save " + this, x);
}
Timer.get().submit(() -> {
try {
getParent().logRotate();
} catch (Exception x) {
LOGGER.log(Level.WARNING, "failed to perform log rotation after " + this, x);
}
});
onEndBuilding();
if (completed != null) {
synchronized (completed) {
completed.set(true);
}
}
FlowExecutionList.get().unregister(new Owner(this));
try {
StashManager.maybeClearAll(this);
} catch (IOException x) {
LOGGER.log(Level.WARNING, "failed to clean up stashes from " + this, x);
}
FlowExecution exec = getExecution();
if (exec != null) {
FlowExecutionListener.fireCompleted(exec);
}
}
use of hudson.AbortException in project gitea-plugin by jenkinsci.
the class GiteaSCMSource method gitea.
/*package*/
Gitea gitea() throws AbortException {
GiteaServer server = GiteaServers.get().findServer(serverUrl);
if (server == null) {
throw new AbortException("Unknown server: " + serverUrl);
}
StandardCredentials credentials = credentials();
SCMSourceOwner owner = getOwner();
if (owner != null) {
CredentialsProvider.track(owner, credentials);
}
return Gitea.server(serverUrl).as(AuthenticationTokens.convert(GiteaAuth.class, credentials));
}
use of hudson.AbortException in project promoted-builds-plugin by jenkinsci.
the class Status method doBuild.
/**
* Schedules a new build.
* @param req Request
* @param rsp Response
* @throws IOException Functional error
* @throws ServletException Request handling error
*/
@POST
public void doBuild(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
final PromotionProcess process = getProcess();
if (process == null) {
throw new AbortException("Cannot retrieve the promotion process");
}
AbstractBuild<?, ?> target = getTarget();
if (target == null) {
throw new AbortException("Cannot get the target build to be promoted");
}
ManualCondition manualCondition = (ManualCondition) process.getPromotionCondition(ManualCondition.class.getName());
// TODO: Use PromotionPermissionHelper.checkPermission instead, but consider issues with backwards compatibility.
if (!PromotionPermissionHelper.hasPermission(target.getProject(), manualCondition)) {
return;
}
JSONObject formData = req.getSubmittedForm();
List<ParameterValue> paramValues = null;
if (formData != null) {
paramValues = new ArrayList<ParameterValue>();
if (manualCondition != null) {
List<ParameterDefinition> parameterDefinitions = manualCondition.getParameterDefinitions();
if (parameterDefinitions != null && !parameterDefinitions.isEmpty()) {
JSONArray a = JSONArray.fromObject(formData.get("parameter"));
for (Object o : a) {
final JSONObject jo;
if (o instanceof JSONObject) {
jo = (JSONObject) o;
} else if (o instanceof JSONNull) {
// ignore nulls
continue;
} else {
throw new IllegalArgumentException("Array type is not supported " + o);
}
String name = jo.getString("name");
ParameterDefinition d = manualCondition.getParameterDefinition(name);
if (d == null)
throw new IllegalArgumentException("No such parameter definition: " + name);
paramValues.add(d.createValue(req, jo));
}
}
}
}
if (paramValues == null) {
paramValues = new ArrayList<ParameterValue>();
}
Future<Promotion> f = process.scheduleBuild2(target, new UserCause(), paramValues);
if (f == null)
LOGGER.warning("Failing to schedule the promotion of " + target);
// TODO: we need better visual feed back so that the user knows that the build happened.
rsp.forwardToPreviousPage(req);
}
use of hudson.AbortException in project promoted-builds-plugin by jenkinsci.
the class FixedResultBuilder method perform.
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
FilePath workspace = build.getWorkspace();
if (workspace == null) {
throw new AbortException("Workspace is missing in FixedResultBuilder");
}
workspace.child("my.file").write("Hello world!", "UTF-8");
build.setResult(buildResult);
return true;
}
use of hudson.AbortException in project hudson-2.x by hudson.
the class WindowsInstallerLink method doDoInstall.
/**
* Performs installation.
*/
public void doDoInstall(StaplerRequest req, StaplerResponse rsp, @QueryParameter("dir") String _dir) throws IOException, ServletException {
if (installationDir != null) {
// installation already complete
sendError("Installation is already complete", req, rsp);
return;
}
if (!DotNet.isInstalled(2, 0)) {
sendError(".NET Framework 2.0 or later is required for this feature", req, rsp);
return;
}
Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
File dir = new File(_dir).getAbsoluteFile();
dir.mkdirs();
if (!dir.exists()) {
sendError("Failed to create installation directory: " + dir, req, rsp);
return;
}
try {
// copy files over there
copy(req, rsp, dir, getClass().getResource("/windows-service/hudson.exe"), "hudson.exe");
copy(req, rsp, dir, getClass().getResource("/windows-service/hudson.xml"), "hudson.xml");
if (!hudsonWar.getCanonicalFile().equals(new File(dir, "hudson.war").getCanonicalFile()))
copy(req, rsp, dir, hudsonWar.toURI().toURL(), "hudson.war");
// install as a service
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamTaskListener task = new StreamTaskListener(baos);
task.getLogger().println("Installing a service");
int r = WindowsSlaveInstaller.runElevated(new File(dir, "hudson.exe"), "install", task, dir);
if (r != 0) {
sendError(baos.toString(), req, rsp);
return;
}
// installation was successful
installationDir = dir;
rsp.sendRedirect(".");
} catch (AbortException e) {
// this exception is used as a signal to terminate processing. the error should have been already reported
} catch (InterruptedException e) {
throw new ServletException(e);
}
}
Aggregations