public boolean apply(R r) { return (r instanceof AbstractBuild) && ((AbstractBuild)r).getBuiltOn()==node; } });
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, TaskListener listener) throws InterruptedException { FilePath ws = build.getWorkspace(); if (ws == null) { Node node = build.getBuiltOn(); if (node == null) { throw new NullPointerException("no such build node: " + build.getBuiltOnStr());
/** * Gets the {@link Node} where this project was last built on. * * @return * null if no information is available (for example, * if no build was done yet.) */ public Node getLastBuiltOn() { // where was it built on? AbstractBuild b = getLastBuild(); if(b==null) return null; else return b.getBuiltOn(); }
@Override protected void calculate(Run<?,?> build, JSONObject element) { BallColor iconColor = build.getIconColor(); element.put("iconColorOrdinal", iconColor.ordinal()); element.put("iconColorDescription", iconColor.getDescription()); element.put("buildStatusUrl", build.getBuildStatusUrl()); element.put("number", build.getNumber()); element.put("displayName", build.getDisplayName()); element.put("duration", build.getDuration()); element.put("durationString", build.getDurationString()); if (build instanceof AbstractBuild) { AbstractBuild<?,?> b = (AbstractBuild) build; Node n = b.getBuiltOn(); if (n == null) { String ns = b.getBuiltOnStr(); if (ns != null && !ns.isEmpty()) { element.put("builtOnStr", ns); } } else if (n != Jenkins.getInstance()) { element.put("builtOn", n.getNodeName()); element.put("builtOnStr", n.getDisplayName()); } else { element.put("builtOnStr", hudson.model.Messages.Hudson_Computer_DisplayName()); } } }
/** * Gets the directory where this build is being built. * * <p> * Note to implementors: to control where the workspace is created, override * {@link AbstractBuildExecution#decideWorkspace(Node,WorkspaceList)}. * * @return * null if the workspace is on an agent that's not connected. Note that once the build is completed, * the workspace may be used to build something else, so the value returned from this method may * no longer show a workspace as it was used for this build. * @since 1.319 */ public final @CheckForNull FilePath getWorkspace() { if (workspace==null) return null; Node n = getBuiltOn(); if (n==null) return null; return n.createPath(workspace); }
private FilePath getFilePath(final AbstractBuild<?, ?> build) { final FilePath ws = build.getWorkspace(); if (ws == null) { final Node node = build.getBuiltOn(); if (node == null) { throw new RuntimeException("no such build node: " + build.getBuiltOnStr()); } throw new RuntimeException("no workspace from node " + node + " which is computer " + node.toComputer() + " and has channel " + node.getChannel()); } return ws; }
/** * Convenient version of {@link #translate(Node, EnvVars, TaskListener)} that just takes a build object in progress. * @since 1.460 */ public ToolInstallation translate(AbstractBuild<?,?> buildInProgress, TaskListener listener) throws IOException, InterruptedException { assert buildInProgress.isBuilding(); return translate(buildInProgress.getBuiltOn(),buildInProgress.getEnvironment(listener),listener); }
private PollingResult pollWithWorkspace(TaskListener listener, SCM scm, R lb, @Nonnull FilePath ws, WorkspaceList l) throws InterruptedException, IOException { // if doing non-concurrent build, acquire a workspace in a way that causes builds to block for this workspace. // this prevents multiple workspaces of the same job --- the behavior of Hudson < 1.319. // // OTOH, if a concurrent build is chosen, the user is willing to create a multiple workspace, // so better throughput is achieved over time (modulo the initial cost of creating that many workspaces) // by having multiple workspaces Node node = lb.getBuiltOn(); Launcher launcher = ws.createLauncher(listener).decorateByEnv(getEnvironment(node,listener)); WorkspaceList.Lease lease = l.acquire(ws, !concurrentBuild); try { String nodeName = node != null ? node.getSelfLabel().getName() : "[node_unavailable]"; listener.getLogger().println("Polling SCM changes on " + nodeName); LOGGER.fine("Polling SCM changes of " + getName()); if (pollingBaseline==null) // see NOTE-NO-BASELINE above calcPollingBaseline(lb,launcher,listener); PollingResult r = scm.poll(this, launcher, ws, listener, pollingBaseline); pollingBaseline = r.remote; return r; } finally { lease.release(); } }
private WorkspaceOfflineReason workspaceOffline(R build) throws IOException, InterruptedException { FilePath ws = build.getWorkspace(); Label label = getAssignedLabel(); if (isAllSuitableNodesOffline(build)) { Collection<Cloud> applicableClouds = label == null ? Jenkins.getInstance().clouds : label.getClouds(); return applicableClouds.isEmpty() ? WorkspaceOfflineReason.all_suitable_nodes_are_offline : WorkspaceOfflineReason.use_ondemand_slave; } if (ws==null || !ws.exists()) { return WorkspaceOfflineReason.nonexisting_workspace; } Node builtOn = build.getBuiltOn(); if (builtOn == null) { // node built-on doesn't exist anymore return WorkspaceOfflineReason.builton_node_gone; } if (builtOn.toComputer() == null) { // node still exists, but has 0 executors - o.s.l.t. return WorkspaceOfflineReason.builton_node_no_executors; } return null; }
return BUILD_NOW; } else { WorkspaceList l = b.getBuiltOn().toComputer().getWorkspaceList(); return pollWithWorkspace(listener, scm, b, ws, l);
/** * Wipes out the workspace. */ @RequirePOST public HttpResponse doDoWipeOutWorkspace() throws IOException, ServletException, InterruptedException { checkPermission(Functions.isWipeOutPermissionEnabled() ? WIPEOUT : BUILD); R b = getSomeBuildWithWorkspace(); FilePath ws = b!=null ? b.getWorkspace() : null; if (ws!=null && getScm().processWorkspaceBeforeDeletion(this, ws, b.getBuiltOn())) { ws.deleteRecursive(); for (WorkspaceListener wl : WorkspaceListener.all()) { wl.afterDelete(this); } return new HttpRedirect("."); } else { // If we get here, that means the SCM blocked the workspace deletion. return new ForwardToView(this,"wipeOutWorkspaceBlocked.jelly"); } }
/** * Filter the list to builds on a single node only */ public RunList<R> node(Node node) { for (Iterator<R> itr = iterator(); itr.hasNext();) { Run r = itr.next(); if (!(r instanceof AbstractBuild) || ((AbstractBuild)r).getBuiltOn()!=node) { itr.remove(); } } return this; }
@Override public String evaluate(AbstractBuild<?, ?> abstractBuild, TaskListener taskListener, String s) throws MacroEvaluationException, IOException, InterruptedException { Node node = abstractBuild.getBuiltOn(); if( node instanceof DockerTransientNode) { return ((DockerTransientNode) node).getContainerId(); } return null; }
/** * If the build was on a cloud, get the ID of that cloud. */ public static Optional<DockerCloud> getCloudForBuild(AbstractBuild build) { Node node = build.getBuiltOn(); if (node instanceof DockerTransientNode) { return Optional.of(((DockerTransientNode) node).getCloud()); } return Optional.empty(); }
/** * Filter the list to builds on a single node only */ public RunList<R> node(Node node) { for (Iterator<R> itr = iterator(); itr.hasNext();) { Run r = itr.next(); if (!(r instanceof AbstractBuild) || ((AbstractBuild)r).getBuiltOn()!=node) { itr.remove(); } } return this; }
/** * Filter the list to builds on a single node only */ public RunList<R> node(Node node) { for (Iterator<R> itr = iterator(); itr.hasNext();) { Run r = itr.next(); if (!(r instanceof AbstractBuild) || ((AbstractBuild)r).getBuiltOn()!=node) { itr.remove(); } } return this; }
/** * Convenient version of {@link #translate(Node, EnvVars, TaskListener)} that just takes a build object in progress. * @since 1.460 */ public ToolInstallation translate(AbstractBuild<?,?> buildInProgress, TaskListener listener) throws IOException, InterruptedException { assert buildInProgress.isBuilding(); return translate(buildInProgress.getBuiltOn(),buildInProgress.getEnvironment(listener),listener); }
public boolean cleanWorkspace() throws IOException, InterruptedException{ checkPermission(BUILD); R b = getSomeBuildWithWorkspace(); FilePath ws = b != null ? b.getWorkspace() : null; if (ws != null && getScm().processWorkspaceBeforeDeletion(this, ws, b.getBuiltOn())) { ws.deleteRecursive(); return true; } else{ // If we get here, that means the SCM blocked the workspace deletion. return false; } }
public boolean cleanWorkspace() throws IOException, InterruptedException { checkPermission(BUILD); R b = getSomeBuildWithWorkspace(); FilePath ws = b != null ? b.getWorkspace() : null; if (ws != null && getScm().processWorkspaceBeforeDeletion(this, ws, b.getBuiltOn())) { ws.deleteRecursive(); return true; } else { // If we get here, that means the SCM blocked the workspace deletion. return false; } }
public boolean cleanWorkspace() throws IOException, InterruptedException{ checkPermission(BUILD); R b = getSomeBuildWithWorkspace(); FilePath ws = b != null ? b.getWorkspace() : null; if (ws != null && getScm().processWorkspaceBeforeDeletion(this, ws, b.getBuiltOn())) { ws.deleteRecursive(); return true; } else{ // If we get here, that means the SCM blocked the workspace deletion. return false; } }