@Override public void buildEnvironmentFor(Job j, EnvVars env, TaskListener listener) throws IOException, InterruptedException { Jenkins jenkins = Jenkins.getInstance(); String rootUrl = jenkins.getRootUrl(); if(rootUrl!=null) { env.put("JENKINS_URL", rootUrl); env.put("HUDSON_URL", rootUrl); // Legacy compatibility env.put("JOB_URL", rootUrl+j.getUrl()); } String root = jenkins.getRootDir().getPath(); env.put("JENKINS_HOME", root); env.put("HUDSON_HOME", root); // legacy compatibility Thread t = Thread.currentThread(); if (t instanceof Executor) { Executor e = (Executor) t; env.put("EXECUTOR_NUMBER", String.valueOf(e.getNumber())); if (e.getOwner() instanceof MasterComputer) { env.put("NODE_NAME", "master"); } else { env.put("NODE_NAME", e.getOwner().getName()); } Node n = e.getOwner().getNode(); if (n != null) env.put("NODE_LABELS", Util.join(n.getAssignedLabels(), " ")); } } }
@Override public void buildEnvironmentFor(Run r, EnvVars env, TaskListener listener) throws IOException, InterruptedException { Computer c = Computer.currentComputer(); if (c!=null){ EnvVars compEnv = c.getEnvironment().overrideAll(env); env.putAll(compEnv); } env.put("BUILD_DISPLAY_NAME",r.getDisplayName()); Jenkins j = Jenkins.getInstance(); String rootUrl = j.getRootUrl(); if(rootUrl!=null) { env.put("BUILD_URL", rootUrl+r.getUrl()); } }
public Builder with(@CheckForNull Computer computer) { if (computer == null) { return this; } if (computer.isOnline()) { final List<Executor> executors = computer.getExecutors(); final boolean acceptingTasks = computer.isAcceptingTasks(); for (Executor e : executors) { definedExecutors++; onlineExecutors++; if (e.getCurrentWorkUnit() != null) { busyExecutors++; } else { idleExecutors++; if (acceptingTasks) availableExecutors++; } } } else { final int numExecutors = computer.getNumExecutors(); definedExecutors += numExecutors; if (computer.isConnecting()) { connectingExecutors += numExecutors; } } return this; }
@Override public int computeIdleExecutors() { int r=0; for (Computer c : Jenkins.getInstance().getComputers()) { Node node = c.getNode(); if (node != null && node.getMode() == Mode.NORMAL && (c.isOnline() || c.isConnecting()) && c.isAcceptingTasks()) { r += c.countIdle(); } } return r; }
@Override public int computeTotalExecutors() { int r=0; for (Computer c : Jenkins.getInstance().getComputers()) { Node node = c.getNode(); if (node != null && node.getMode() == Mode.NORMAL && c.isOnline()) { r += c.countExecutors(); } } return r; }
@Override public String getStatus() { // Yet another copy of the same logic; perhaps this should be factored into some method returning a union of Queue.Item and PlaceholderExecutable? for (Queue.Item item : Queue.getInstance().getItems()) { if (item.task instanceof PlaceholderTask && ((PlaceholderTask) item.task).context.equals(getContext())) { return "waiting for " + item.task.getFullDisplayName() + " to be scheduled; blocked: " + item.getWhy(); } } Jenkins j = Jenkins.getInstance(); if (j != null) { COMPUTERS: for (Computer c : j.getComputers()) { for (Executor e : c.getExecutors()) { Queue.Executable exec = e.getCurrentExecutable(); if (exec instanceof PlaceholderTask.PlaceholderExecutable && ((PlaceholderTask.PlaceholderExecutable) exec).getParent().context.equals(getContext())) { return "running on " + c.getName(); } } } } return "node block appears to be neither running nor scheduled"; }
final Computer computer = workspace.toComputer(); if (computer == null) { throw new AbortException("Cannot get Coverity tools installation"); final Node node = computer.getNode(); if (node == null) { throw new AbortException("Cannot get Coverity tools installation"); final EnvVars covEnvVars = new EnvVars(); covTools.buildEnvVars(covEnvVars); final CoverityPublisher.DescriptorImpl descriptor = Jenkins.getInstance().getDescriptorByType(CoverityPublisher.DescriptorImpl.class); CIMInstance instance = descriptor.getInstance(connectInstance); if (instance != null) { covEnvVars.put(StringUtils.isNotEmpty(hostVariable) ? hostVariable : "COVERITY_HOST", instance.getHost()); covEnvVars.put(StringUtils.isNotEmpty(portVariable) ? portVariable : "COVERITY_PORT", String.valueOf(instance.getPort())); covEnvVars.put(StringUtils.isNotEmpty(usernameVariable) ? usernameVariable : "COV_USER", instance.getCoverityUser()); covEnvVars.put(StringUtils.isNotEmpty(passwordVariable) ? passwordVariable : "COVERITY_PASSPHRASE", instance.getCoverityPassword());
/** * 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; }
@Override public void stop(Throwable cause) throws Exception { for (Queue.Item item : Queue.getInstance().getItems()) { // if we are still in the queue waiting to be scheduled, just retract that if (item.task instanceof PlaceholderTask && ((PlaceholderTask) item.task).context.equals(getContext())) { Queue.getInstance().cancel(item); break; } } Jenkins j = Jenkins.getInstance(); if (j != null) { // if we are already running, kill the ongoing activities, which releases PlaceholderExecutable from its sleep loop // Similar to Executor.of, but distinct since we do not have the Executable yet: COMPUTERS: for (Computer c : j.getComputers()) { for (Executor e : c.getExecutors()) { Queue.Executable exec = e.getCurrentExecutable(); if (exec instanceof PlaceholderTask.PlaceholderExecutable && ((PlaceholderTask.PlaceholderExecutable) exec).getParent().context.equals(getContext())) { PlaceholderTask.finish(((PlaceholderTask.PlaceholderExecutable) exec).getParent().cookie); break COMPUTERS; } } } } // Whether or not either of the above worked (and they would not if for example our item were canceled), make sure we die. super.stop(cause); }
listener.getLogger().println("no previous build to compare to"); return Queue.getInstance().contains(this) ? PollingResult.NO_CHANGES : PollingResult.BUILD_NOW; WorkspaceList.Lease lease; if (co.scm.requiresWorkspaceForPolling()) { Jenkins j = Jenkins.getInstance(); if (j == null) { listener.error("Jenkins is shutting down"); continue; Computer c = j.getComputer(co.node); if (c == null) { listener.error("no such computer " + co.node); continue; workspace = new FilePath(c.getChannel(), co.workspace); launcher = workspace.createLauncher(listener).decorateByEnv(getEnvironment(c.getNode(), listener)); lease = c.getWorkspaceList().acquire(workspace, !isConcurrentBuild()); } else { workspace = null; listener.error("polling failed in " + co.workspace + " on " + co.node + ": " + x.getMessage()); } catch (Exception x) { listener.error("polling failed in " + co.workspace + " on " + co.node).println(Functions.printThrowable(x).trim()); // TODO 2.43+ use Functions.printStackTrace
targets = env.expand(targets); String pom = env.expand(this.pom); MavenInstallation mi = getMaven(); if(mi==null) { String execName = build.getWorkspace().act(new DecideDefaultMavenCommand(normalizedTarget)); args.add(execName); } else { mi = mi.forNode(Computer.currentComputer().getNode(), listener); mi = mi.forEnvironment(env); String exec = mi.getExecutable(launcher); args.add("-Dmaven.repo.local=" + build.getWorkspace().child(".repository")); args.addTokenized(normalizedTarget); wrapUpArguments(args,normalizedTarget,build,launcher,listener);
/** * 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() + '/'); }
Queue queue = Queue.getInstance(); if (this instanceof Queue.Task) { queue.cancel((Queue.Task) this); for (Queue.Item i : queue.getItems()) { Item item = ItemDeletion.getItemOf(i.task); while (item != null) { for (Computer c : Jenkins.getActiveInstance().getComputers()) { for (Executor e : c.getExecutors()) { WorkUnit workUnit = e.getCurrentWorkUnit(); if (workUnit != null) { Item item = ItemDeletion.getItemOf(getParentOf(workUnit.getExecutable())); while (item != null) { if (item == this) { buildsInProgress.put(e, e.getCurrentExecutable()); e.interrupt(Result.ABORTED); break; for (Executor e : c.getOneOffExecutors()) { WorkUnit workUnit = e.getCurrentWorkUnit(); if (workUnit != null) { Jenkins.getActiveInstance().rebuildDependencyGraphAsync();
protected DiskSpace getFreeSpace(Computer c) throws IOException, InterruptedException { FilePath p = c.getNode().getRootPath(); if(p==null) return null; return p.act(new GetTempSpace()); } };
Jenkins j = Jenkins.getInstance(); for (Computer c : j.getComputers()) { if (c.getChannel() == launcher.getChannel()) { node = c.getName(); break; throw new AbortException("Could not find computer for the job"); computer = j.getComputer(node); if (computer == null) { throw new AbortException("No such computer " + node); LOGGER.log(Level.FINE, "Computer: {0}", computer.getName()); try { LOGGER.log(Level.FINE, "Env: {0}", computer.getEnvironment()); } catch (IOException | InterruptedException e) {// ignored
/** * Setup the selected JDK. If none is provided nothing is done. */ private void setupJDK() throws AbortException, IOException, InterruptedException { String jdkInstallationName = step.getJdk(); if (StringUtils.isEmpty(jdkInstallationName)) { console.println("[withMaven] using JDK installation provided by the build agent"); return; } if (withContainer) { // see #detectWithContainer() LOGGER.log(Level.FINE, "Ignoring JDK installation parameter: {0}", jdkInstallationName); console.println("WARNING: \"withMaven(){...}\" step running within a container," + " tool installations are not available see https://issues.jenkins-ci.org/browse/JENKINS-36159. " + "You have specified a JDK installation \"" + jdkInstallationName + "\", which will be ignored."); return; } console.println("[withMaven] using JDK installation " + jdkInstallationName); JDK jdk = Jenkins.getInstance().getJDK(jdkInstallationName); if (jdk == null) { throw new AbortException("Could not find the JDK installation: " + jdkInstallationName + ". Make sure it is configured on the Global Tool Configuration page"); } Node node = getComputer().getNode(); if (node == null) { throw new AbortException("Could not obtain the Node for the computer: " + getComputer().getName()); } jdk = jdk.forNode(node, listener).forEnvironment(env); jdk.buildEnvVars(envOverride); }
/** * Gets the one off {@link Executor} building this job, if it's being built. * Otherwise null. * @since 1.433 */ public @CheckForNull Executor getOneOffExecutor() { for( Computer c : Jenkins.getInstance().getComputers() ) { for (Executor e : c.getOneOffExecutors()) { if(e.getCurrentExecutable()==this) return e; } } return null; }
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("Starting Selenium nodes on " + ("".equals(c.getName()) ? "(master)" : c.getName()));
void broadcast() { for (Computer c : Jenkins.getInstance().getComputers()) { if (c.getName().length() > 0) { // i.e. not master VirtualChannel ch = c.getChannel(); if (ch != null) { try { ch.call(this); } catch (Exception x) { Logger.getLogger(LogRecorder.class.getName()).log(Level.WARNING, "could not set up logging on " + c, x); } } } } } }