use of hudson.model.Run in project hudson-2.x by hudson.
the class InstallToolCommand method install.
/**
* Performs an installation.
*/
private int install(ToolInstallation t, BuildIDs id, AbstractProject p) throws IOException, InterruptedException {
Run b = p.getBuildByNumber(Integer.parseInt(id.number));
if (b == null)
throw new AbortException("No such build: " + id.number);
Executor exec = b.getExecutor();
if (exec == null)
throw new AbortException(b.getFullDisplayName() + " is not building");
Node node = exec.getOwner().getNode();
if (t instanceof NodeSpecific) {
NodeSpecific n = (NodeSpecific) t;
t = (ToolInstallation) n.forNode(node, new StreamTaskListener(stderr));
}
if (t instanceof EnvironmentSpecific) {
EnvironmentSpecific e = (EnvironmentSpecific) t;
t = (ToolInstallation) e.forEnvironment(EnvVars.getRemote(channel));
}
stdout.println(t.getHome());
return 0;
}
use of hudson.model.Run in project hudson-2.x by hudson.
the class Functions method decompose.
public static RunUrl decompose(StaplerRequest req) {
List<Ancestor> ancestors = req.getAncestors();
// find the first and last Run instances
Ancestor f = null, l = null;
for (Ancestor anc : ancestors) {
if (anc.getObject() instanceof Run) {
if (f == null)
f = anc;
l = anc;
}
}
// there was no Run object
if (l == null)
return null;
String head = f.getPrev().getUrl() + '/';
String base = l.getUrl();
String reqUri = req.getOriginalRequestURI();
// Find "rest" or URI by removing N path components.
// Not using reqUri.substring(f.getUrl().length()) to avoid mismatches due to
// url-encoding or extra slashes. Former may occur in Tomcat (despite the spec saying
// this string is not decoded, Tomcat apparently decodes this string. You see ' '
// instead of '%20', which is what the browser has sent), latter may occur in some
// proxy or URL-rewriting setups where extra slashes are inadvertently added.
String furl = f.getUrl();
int slashCount = 0;
// Count components in ancestor URL
for (int i = furl.indexOf('/'); i >= 0; i = furl.indexOf('/', i + 1)) slashCount++;
// Remove that many from request URL, ignoring extra slashes
String rest = reqUri.replaceFirst("(?:/+[^/]*){" + slashCount + "}", "");
return new RunUrl((Run) f.getObject(), head, base, rest);
}
use of hudson.model.Run in project hudson-2.x by hudson.
the class LogRotator method deleteBuilds.
/**
* Performs builds deletion
*
* @param builds list of builds
* @param lastSuccessBuild last success build
* @param lastStableBuild last stable build
* @param cal calendar if configured
* @throws IOException if configured
*/
private void deleteBuilds(List<? extends Run<?, ?>> builds, Run lastSuccessBuild, Run lastStableBuild, Calendar cal) throws IOException {
for (Run currentBuild : builds) {
if (allowDeleteBuild(lastSuccessBuild, lastStableBuild, currentBuild, cal)) {
LOGGER.log(FINER, currentBuild.getFullDisplayName() + " is to be removed");
currentBuild.delete();
}
}
}
use of hudson.model.Run in project blueocean-plugin by jenkinsci.
the class PipelineNodeUtil method getCauseOfBlockage.
/**
* Gives cause of block for declarative style plugin where agent (node block) is declared inside a stage.
* <pre>
* pipeline {
* agent none
* stages {
* stage ('first') {
* agent {
* label 'first'
* }
* steps{
* sh 'echo "from first"'
* }
* }
* }
* }
* </pre>
*
* @param stage stage's {@link FlowNode}
* @param nodeBlock agent or node block's {@link FlowNode}
* @param run {@link WorkflowRun} instance
* @return cause of block if present, nul otherwise
* @throws IOException in case of IOException
* @throws InterruptedException in case of Interrupted exception
*/
@CheckForNull
public static String getCauseOfBlockage(@Nonnull FlowNode stage, @Nullable FlowNode nodeBlock, @Nonnull WorkflowRun run) throws IOException, InterruptedException {
if (nodeBlock != null) {
//Check and see if this node block is inside this stage
for (FlowNode p : nodeBlock.getParents()) {
if (p.equals(stage)) {
//see if there is blocked item in queue
for (Queue.Item i : Jenkins.getInstance().getQueue().getItems()) {
if (i.task instanceof ExecutorStepExecution.PlaceholderTask) {
ExecutorStepExecution.PlaceholderTask task = (ExecutorStepExecution.PlaceholderTask) i.task;
String cause = i.getCauseOfBlockage().getShortDescription();
if (task.getCauseOfBlockage() != null) {
cause = task.getCauseOfBlockage().getShortDescription();
}
Run r = task.runForDisplay();
//Set cause if its there and run and node block in the queue is same as the one we
if (cause != null && r != null && r.equals(run) && task.getNode() != null && task.getNode().equals(nodeBlock)) {
return cause;
}
}
}
}
}
}
return null;
}
use of hudson.model.Run in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method getPipelineJobRunsTest.
@Test
public void getPipelineJobRunsTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build1'); " + " echo ('Building'); " + " stage ('Test1'); " + " echo ('Testing'); " + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
WorkflowRun b2 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b2);
Run[] runs = { b2, b1 };
List<Map> runResponses = get("/organizations/jenkins/pipelines/pipeline1/runs", List.class);
for (int i = 0; i < runs.length; i++) {
validateRun(runs[i], runResponses.get(i));
}
;
}
Aggregations