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; }
/** * Accepts the update to the node configuration. */ @RequirePOST public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException { checkPermission(CONFIGURE); String proposedName = Util.fixEmptyAndTrim(req.getSubmittedForm().getString("name")); Jenkins.checkGoodName(proposedName); Node node = getNode(); if (node == null) { throw new ServletException("No such node " + nodeName); } if ((!proposedName.equals(nodeName)) && Jenkins.getActiveInstance().getNode(proposedName) != null) { throw new FormException(Messages.ComputerSet_SlaveAlreadyExists(proposedName), "name"); } String nExecutors = req.getSubmittedForm().getString("numExecutors"); if (StringUtils.isBlank(nExecutors) || Integer.parseInt(nExecutors)<=0) { throw new FormException(Messages.Slave_InvalidConfig_Executors(nodeName), "numExecutors"); } Node result = node.reconfigure(req, req.getSubmittedForm()); Jenkins.getInstance().getNodesObject().replaceNode(this.getNode(), result); // take the user back to the agent top page. rsp.sendRedirect2("../" + result.getNodeName() + '/'); }
public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { FilePath expected = preferredLocation(tool, node); Installable inst = getInstallable(); if(inst==null) { log.getLogger().println("Invalid tool ID "+id); return expected; } if (inst instanceof NodeSpecific) { inst = (Installable) ((NodeSpecific) inst).forNode(node, log); } if(isUpToDate(expected,inst)) return expected; if(expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) { expected.child(".timestamp").delete(); // we don't use the timestamp FilePath base = findPullUpDirectory(expected); if(base!=null && base!=expected) base.moveAllChildrenTo(expected); // leave a record for the next up-to-date check expected.child(".installedFrom").write(inst.url,"UTF-8"); expected.act(new ZipExtractionInstaller.ChmodRecAPlusX()); } return expected; }
public String getShortDescription() { String name = (node.toComputer() != null) ? node.toComputer().getDisplayName() : node.getDisplayName(); return Messages.Queue_NodeOffline(name); }
public static String encodeTo(Node node) { Computer c = node.toComputer(); if (c != null) { return encodeTo("/" + c.getUrl(), node.getDisplayName()); } String nodePath = node == Jenkins.getInstance() ? "(master)" : node.getNodeName(); return encodeTo("/computer/" + nodePath, node.getDisplayName()); }
/** * Estimates the clock difference with this agent. * * @return * always non-null. * @throws InterruptedException * if the operation is aborted. */ public ClockDifference getClockDifference() throws IOException, InterruptedException { VirtualChannel channel = getChannel(); if(channel==null) throw new IOException(getNodeName()+" is offline"); return channel.call(getClockDifferenceCallable()); }
listener.getLogger().println("Checking " + item.getFullDisplayName()); for (Node node : nodes) { FilePath ws = node.getWorkspaceFor(item); if (ws == null) { continue; // offline, fine check = shouldBeDeleted(item, ws, node); } catch (IOException x) { Functions.printStackTrace(x, listener.error("Failed to check " + node.getDisplayName())); continue; } catch (InterruptedException x) { Functions.printStackTrace(x, listener.error("Failed to check " + node.getDisplayName())); continue; listener.getLogger().println("Deleting " + ws + " on " + node.getDisplayName()); try { ws.deleteRecursive(); WorkspaceList.tempDir(ws).deleteRecursive(); } catch (IOException x) { Functions.printStackTrace(x, listener.error("Failed to delete " + ws + " on " + node.getDisplayName())); } catch (InterruptedException x) { Functions.printStackTrace(x, listener.error("Failed to delete " + ws + " on " + node.getDisplayName()));
@Override public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { FilePath dir = preferredLocation(tool, node); // TODO support Unix scripts with interpreter line (see Shell.buildCommandLine) FilePath script = dir.createTextTempFile("hudson", getCommandFileExtension(), command); try { String cmd[] = getCommandCall(script); int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join(); if (r != 0) { throw new IOException("Command returned status " + r); } } finally { script.delete(); } return dir.child(getToolHome()); }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws IOException, InterruptedException { String customWorkspace = getProject().getCustomWorkspace(); if (customWorkspace != null) { // we allow custom workspaces to be concurrently used between jobs. return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace))); } return super.decideWorkspace(n, wsl); }
List<Node> nodes = Jenkins.getInstance().getNodes(); for (Node node : nodes) { if (node == null || node.getChannel() == null) { continue; List<DockerImage> partialDockerImages = node.getChannel().call(new MasterToSlaveCallable<List<DockerImage>, IOException>() { public List<DockerImage> call() throws IOException { List<DockerImage> dockerImages = new ArrayList<DockerImage>(); dockerImages.addAll(partialDockerImages); } catch (Exception e) { listener.getLogger().println("Could not collect docker images from Jenkins node '" + node.getDisplayName() + "' due to: " + e.getMessage());
/** * Creates an environment variable override to be used for launching processes on this node. * * @see ProcStarter#envs(Map) * @since 1.489 */ public @Nonnull EnvVars buildEnvironment(@Nonnull TaskListener listener) throws IOException, InterruptedException { EnvVars env = new EnvVars(); Node node = getNode(); if (node==null) return env; // bail out for (NodeProperty nodeProperty: Jenkins.getInstance().getGlobalNodeProperties()) { nodeProperty.buildEnvVars(env,listener); } for (NodeProperty nodeProperty: node.getNodeProperties()) { nodeProperty.buildEnvVars(env,listener); } // TODO: hmm, they don't really belong String rootUrl = Jenkins.getInstance().getRootUrl(); if(rootUrl!=null) { env.put("HUDSON_URL", rootUrl); // Legacy. env.put("JENKINS_URL", rootUrl); } return env; }
public static void startSeleniumNode(Computer c, TaskListener listener, String conf) throws IOException, InterruptedException { LOGGER.fine("Examining if we need to start Selenium Grid Node"); final PluginImpl p = Jenkins.getInstance().getPlugin(PluginImpl.class); for (Label label : c.getNode().getAssignedLabels()) { for (String pattern : exclusionPatterns) { if (label.toString().matches(pattern)) { LOGGER.fine("Node " + c.getNode().getDisplayName() + " is excluded from Selenium Grid because its label '" + label + "' matches exclusion pattern '" + pattern + "'"); return; listener.getLogger().println( "Unable to determine the host name of the master. Skipping Selenium execution. " + "Please " + HyperlinkNote.encodeTo("/configure", "configure the Jenkins URL") + " from the system configuration screen."); listener.getLogger().println("Starting Selenium nodes on " + ("".equals(c.getName()) ? "(master)" : c.getName()));
/** * Get the home directory for the given node. * * @param node * The node * @return The home directory */ public static FilePath get(Node node) { // Get the potential properties WorkspaceHomeProperty[] properties = new WorkspaceHomeProperty[] { node.getNodeProperties().get(WorkspaceHomeProperty.class), Jenkins.getInstance().getGlobalNodeProperties().get(WorkspaceHomeProperty.class) }; // Go threw the properties for (WorkspaceHomeProperty property : properties) // Check if exists if (property != null) // Check if valid if (Util.fixEmpty(property.getHome()) != null) // Return the home folder return new FilePath(node.getChannel(), property.getHome()); // Else relative to root return node.getRootPath().child(Workspace.BASENAME).child("jobs"); }
@Override public List<AbstractBuildParameters> getParameters(AbstractBuild<?, ?> build, TaskListener listener) { Computer[] nodes = Jenkins.getInstance().getComputers(); final PrintStream logger = listener.getLogger(); List<AbstractBuildParameters> params = Lists.newArrayList(); for(Computer c : nodes) { Node n = c.getNode(); if (n!=null && c.isOnline() && c.getNumExecutors()>0) { params.add(new NodeLabelBuildParameter("label", n.getSelfLabel().getName())); logger.println("trigger build on "+n.getDisplayName() +" ("+n.getSelfLabel().getName()+")"); } } return params; }
public String getToolHome(Node node, ToolInstallation tool, TaskListener log) throws IOException, InterruptedException { if (node.getRootPath() == null) { log.error(node.getDisplayName() + " is offline; cannot locate " + tool.getName()); return null; return installer.performInstallation(tool, node, log).getRemote(); } finally { semaphore.release(); installer.getDescriptor().getDisplayName(), tool.getName(), node.getDisplayName())); log.getLogger().println(message);
protected Lease getParentWorkspaceLease(final Node n, final WorkspaceList wsl) throws InterruptedException, IOException { final DynamicProject mp = getParent().getParent(); final String customWorkspace = mp.getCustomWorkspace(); if (customWorkspace != null) { // we allow custom workspaces to be concurrently used between // jobs. return Lease.createDummyLease(n.getRootPath().child(getEnvironment(this.listener).expand(customWorkspace))); } return wsl.allocate(n.getWorkspaceFor(mp), getParentBuild()); }
long running = Jenkins.getInstance().getInjector().getInstance(Uptime.class).getUptime(); long remaining = TimeUnit.MINUTES.toMillis(10)-running; if (remaining>0 && /* this logic breaks tests of polling */!Functions.getIsUnitTest()) { listener.getLogger().print(Messages.AbstractProject_AwaitingWorkspaceToComeOnline(remaining/1000)); listener.getLogger().println( " (" + workspaceOfflineReason.name() + ")"); return NO_CHANGES; listener.getLogger().print(Messages.AbstractProject_AwaitingWorkspaceToComeOnline(running/1000)); listener.getLogger().println( " (" + workspaceOfflineReason.name() + ")"); return NO_CHANGES; if (label != null && label.isSelfLabel()) { return BUILD_NOW; } else { WorkspaceList l = b.getBuiltOn().toComputer().getWorkspaceList(); return pollWithWorkspace(listener, scm, b, ws, l);
@Override public Action getAction(AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException, DontTriggerException { Node node = build.getBuiltOn(); Label nodeLabel; // master does not return a node name so add it explicitly. if(node == null) { nodeLabel = Jenkins.getInstance().getSelfLabel(); } else { nodeLabel = node.getSelfLabel(); } listener.getLogger().println("Returning node parameter for " + nodeLabel.getDisplayName()); return new NodeAction(nodeLabel); }
List<Node> allNodes = Jenkins.getInstance().getNodes(); if(label.getNodes().isEmpty()) { return false; return label.isOffline(); } else { if(canRoam) { for (Node n : Jenkins.getInstance().getNodes()) { Computer c = n.toComputer(); if (c != null && c.isOnline() && c.isAcceptingTasks() && n.getMode() == Mode.NORMAL) {
static void doRetrieve(String name, boolean changelog, @Nonnull SCM scm, FilePath target, Run<?, ?> run, TaskListener listener) throws Exception { // Adapted from CpsScmFlowDefinition: SCMStep delegate = new GenericSCMStep(scm); delegate.setPoll(false); // TODO we have no API for determining if a given SCMHead is branch-like or tag-like; would we want to turn on polling if the former? delegate.setChangelog(changelog); FilePath dir; Node node = Jenkins.getActiveInstance(); if (run.getParent() instanceof TopLevelItem) { FilePath baseWorkspace = node.getWorkspaceFor((TopLevelItem) run.getParent()); if (baseWorkspace == null) { throw new IOException(node.getDisplayName() + " may be offline"); } dir = baseWorkspace.withSuffix(getFilePathSuffix() + "libs").child(name); } else { // should not happen, but just in case: throw new AbortException("Cannot check out in non-top-level build"); } Computer computer = node.toComputer(); if (computer == null) { throw new IOException(node.getDisplayName() + " may be offline"); } try (WorkspaceList.Lease lease = computer.getWorkspaceList().allocate(dir)) { delegate.checkout(run, lease.path, listener, node.createLauncher(listener)); // Cannot add WorkspaceActionImpl to private CpsFlowExecution.flowStartNodeActions; do we care? // Copy sources with relevant files from the checkout: lease.path.copyRecursiveTo("src/**/*.groovy,vars/*.groovy,vars/*.txt,resources/", null, target); } }