Refine search
public static StreamTaskListener fromStdout() { return new StreamTaskListener(System.out,Charset.defaultCharset()); }
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); StreamTaskListener task = new StreamTaskListener(baos); task.getLogger().println("Installing a service"); int r = runElevated(new File(dir, "jenkins.exe"), "install", task, dir); if(r!=0) {
public void run() { logger.log(getNormalLoggingLevel(), "Started {0}", name); long startTime = System.currentTimeMillis(); long stopTime; StreamTaskListener l = createListener(); try { l.getLogger().printf("Started at %tc%n", new Date(startTime)); ACL.impersonate(ACL.SYSTEM); execute(l); } catch (IOException e) { Functions.printStackTrace(e, l.fatalError(e.getMessage())); } catch (InterruptedException e) { Functions.printStackTrace(e, l.fatalError("aborted")); } finally { stopTime = System.currentTimeMillis(); try { l.getLogger().printf("Finished at %tc. %dms%n", new Date(stopTime), stopTime - startTime); } finally { l.closeQuietly(); } } logger.log(getNormalLoggingLevel(), "Finished {0}. {1,number} ms", new Object[]{name, stopTime - startTime}); } },name+" thread");
private boolean runPolling() { try { // to make sure that the log file contains up-to-date text, // don't do buffering. StreamTaskListener listener = new StreamTaskListener(getLogFile()); try { PrintStream logger = listener.getLogger(); long start = System.currentTimeMillis(); logger.println("Started on "+ DateFormat.getDateTimeInstance().format(new Date())); boolean result = job().poll(listener).hasChanges(); logger.println("Done. Took "+ Util.getTimeSpanString(System.currentTimeMillis()-start)); if(result) logger.println("Changes found"); else logger.println("No changes"); return result; } catch (Error | RuntimeException e) { Functions.printStackTrace(e, listener.error("Failed to record SCM polling for " + job)); LOGGER.log(Level.SEVERE,"Failed to record SCM polling for "+job,e); throw e; } finally { listener.close(); } } catch (IOException e) { LOGGER.log(Level.SEVERE,"Failed to record SCM polling for "+job,e); return false; } }
@Override public void restart() throws IOException, InterruptedException { Jenkins jenkins = Jenkins.getInstanceOrNull(); try { if (jenkins != null) { jenkins.cleanUp(); } } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to clean up. Restart will continue.", e); } File me = getHudsonWar(); File home = me.getParentFile(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamTaskListener task = new StreamTaskListener(baos); task.getLogger().println("Restarting a service"); String exe = System.getenv("WINSW_EXECUTABLE"); File executable; if (exe!=null) executable = new File(exe); else executable = new File(home, "hudson.exe"); if (!executable.exists()) executable = new File(home, "jenkins.exe"); // use restart! to run hudson/jenkins.exe restart in a separate process, so it doesn't kill itself int r = new LocalLauncher(task).launch().cmds(executable, "restart!") .stdout(task).pwd(home).join(); if(r!=0) throw new IOException(baos.toString()); }
throw new IllegalStateException("Already connected"); final TaskListener taskListener = launchLog != null ? new StreamTaskListener(launchLog) : TaskListener.NULL; PrintStream log = taskListener.getLogger(); if (Util.isRelativePath(remoteFS)) { remoteFS = channel.call(new AbsolutePath(remoteFS)); log.println("NOTE: Relative remote path resolved to: "+remoteFS); this.channel = channel; this.absoluteRemoteFs = remoteFS; defaultCharset = Charset.forName(defaultCharsetName); Jenkins.get().getQueue().scheduleMaintenance();
/** * Releases and removes this agent. */ public void terminate() throws InterruptedException, IOException { final Computer computer = toComputer(); if (computer != null) { computer.recordTermination(); } try { // TODO: send the output to somewhere real _terminate(new StreamTaskListener(System.out, Charset.defaultCharset())); } finally { try { Jenkins.get().removeNode(this); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to remove "+name,e); } } }
/** * Used for experimenting the memory leak problem. * This test by itself doesn't detect that, but I'm leaving it in anyway. */ @Issue("JENKINS-8061") @Test public void pollingLeak() throws Exception { Proc p = runSvnServe(getClass().getResource("small.zip")); try { FreeStyleProject b = r.createFreeStyleProject(); b.setScm(new SubversionSCM("svn://localhost/")); b.setAssignedNode(r.createSlave()); r.assertBuildStatusSuccess(b.scheduleBuild2(0)); b.poll(new StreamTaskListener(System.out,Charset.defaultCharset())); } finally { p.kill(); } }
@Test public void triggersNewBuild() throws Exception { TaskListener listener = new StreamTaskListener(System.out, Charset.defaultCharset()); Launcher launcher = j.jenkins.createLauncher(listener); FreeStyleProject project = j.createFreeStyleProject(); // TODO switch to MercurialContainer MercurialSCM scm = new MercurialSCM(null, tmp.getRoot().getPath(), null, null, null, null, false, null); project.setScm(scm); File repo = tmp.getRoot(); m.hg(repo, "init"); m.touchAndCommit(repo, "x"); PollingResult pr = scm.compare( launcher, listener, new MercurialTagAction("tip","",null,null), listener.getLogger(), j.jenkins, new FilePath(tmp.getRoot()), project); assertEquals(PollingResult.Change.SIGNIFICANT, pr.change); }
public PollingResult pollSCMChanges(FreeStyleProject p) { return p.poll(new StreamTaskListener(System.out, Charset .defaultCharset())); }
@Before public void setUp() throws Exception { this.mercurialInstallation = new MercurialInstallation( INSTALLATION, "", "hg", false, true, false, Collections .<ToolProperty<?>> emptyList()); this.listener = new StreamTaskListener(System.out, Charset.defaultCharset()); this.launcher = j.jenkins.createLauncher(listener); this.vars = new EnvVars(); }
JCloudsSlave doProvisionFromTemplate(final JCloudsSlaveTemplate t) throws IOException { final StringWriter sw = new StringWriter(); final StreamTaskListener listener = new StreamTaskListener(sw); final ProvisioningActivity.Id provisioningId = new ProvisioningActivity.Id(this.name, t.name); JCloudsSlave node = t.provisionSlave(listener, provisioningId); Jenkins.getInstance().addNode(node); return node; }
Jenkins hudson = Jenkins.getInstance(); hudson.checkPermission(Jenkins.ADMINISTER); StreamTaskListener listener = new StreamTaskListener(log); try { datasetName = createZfsFileSystem(listener,username,password); } catch (Exception e) { Functions.printStackTrace(e, listener.error(e.getMessage()));
SecurityContext oldContext = ACL.impersonate(ACL.SYSTEM); try { Jenkins jenkins = Jenkins.getInstance(); if (jenkins == null) { return; File logFile = new File(new File(jenkins.getRootDir(), "logs"), "health-checker.log"); if (!logFile.isFile()) { File oldFile = new File(jenkins.getRootDir(), HealthChecker.class.getName() + ".log"); if (!logFile.getParentFile().isDirectory() && !logFile.getParentFile().mkdirs()) { logger.log(Level.SEVERE, "Could not create logs directory: {0}", logFile.getParentFile()); l = new StreamTaskListener(logFile); execute(l); } catch (IOException e) { if (l != null) { e.printStackTrace(l.fatalError(e.getMessage())); } else { logger.log(Level.SEVERE, e.printStackTrace(l.fatalError("aborted")); } catch (Exception e) { logger.log(Level.SEVERE, "Error running " + HealthChecker.class.getName(), e); if (l != null) { e.printStackTrace(l.fatalError(e.getMessage())); l.closeQuietly();
@Override public void stop() throws Exception { for (Computer c : Jenkins.getInstance().getComputers()) { for (SeleniumGlobalConfiguration cfg : configurations) { cfg.stop(c); } } this.listener.closeQuietly(); channel.close(); }
public Node call() throws Exception { // TODO: record the output somewhere JCloudsSlave jcloudsSlave = template.provisionSlave(StreamTaskListener.fromStdout(), provisioningId); Jenkins.getInstance().addNode(jcloudsSlave); /* Cloud instances may have a long init script. If we declare the provisioning complete by returning without the connect operation, NodeProvisioner may decide that it still wants one more instance, because it sees that (1) all the slaves are offline (because it's still being launched) and (2) there's no capacity provisioned yet. Deferring the completion of provisioning until the launch goes successful prevents this problem. */ ensureLaunched(jcloudsSlave); return jcloudsSlave; } })));
lastRotateMillis = System.currentTimeMillis(); File oldFile = new File(Jenkins.getActiveInstance().getRootDir(), f.getName()); if (oldFile.isFile()) { File newFile = new File(f.getParentFile(), f.getName() + ".1"); return new StreamTaskListener(f, true, null); } catch (IOException e) { throw new Error(e);
MercurialInstallation installation = new MercurialInstallation(instName, "", "hg", false, true, false, null, null); LogTaskListener listener = new LogTaskListener(Logger.getLogger(getClass().getName()), Level.INFO); final HgExe hg = new HgExe(installation, null, r.jenkins.createLauncher( listener), r.jenkins, listener, new EnvVars()); String version; sampleRepo.child("file").write("initial content", null); m.hg(sampleRepo, "commit", "--addremove", "--message=flow"); WorkflowMultiBranchProject mp = r.jenkins.createProject(WorkflowMultiBranchProject.class, "p"); r.jenkins.getDescriptorByType(MercurialInstallation.DescriptorImpl.class).setInstallations(installation); installation.forNode(r.jenkins, StreamTaskListener.fromStdout()); mp.getSourcesList().add(new BranchSource(new MercurialSCMSource(null, instName, sampleRepo.toURI().toString(), null, null, null, null, null, true))); WorkflowJob p = scheduleAndFindBranchProject(mp, "default"); r.waitUntilNoActivity(); WorkflowRun b1 = p.getLastBuild(); assertNotNull(b1); r.waitUntilNoActivity(); WorkflowRun b2 = p.getLastBuild(); assertEquals(2, b2.getNumber()); r.assertLogContains("initial content", r.assertBuildStatusSuccess(b1)); r.assertLogContains("SUBSEQUENT CONTENT", r.assertBuildStatusSuccess(b2)); List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets = b2.getChangeSets();
String.format("'%s' is not a valid parameter. Did you mean %s?", name, nearest)); ParameterValue val = pd.createValue(this, Util.fixNull(e.getValue())); if (val == null) { throw new CmdLineException(null, String.format("Cannot resolve the value for the parameter '%s'.",name)); return 0; if (!item.poll(new StreamTaskListener(stdout, getClientCharset())).hasChanges()) return 0; Queue.Item item = ParameterizedJobMixIn.scheduleBuild2(job, 0, new CauseAction(new CLICause(Jenkins.getAuthentication().getName())), a); QueueTaskFuture<? extends Run<?,?>> f = item != null ? (QueueTaskFuture)item.getFuture() : null;
@Issue("JENKINS-16533") @Test public void pollingRespectExternalsWithRevision() throws Exception { // trunk has svn:externals="-r 1 ^/vendor vendor" (pinned) // latest commit on vendor is r3 (> r1) File repo = new CopyExisting(getClass().getResource("JENKINS-16533.zip")).allocate(); SubversionSCM scm = new SubversionSCM("file://" + repo.toURI().toURL().getPath() + "trunk"); // pinned externals should be recorded with ::p in revisions.txt FreeStyleProject p = r.createFreeStyleProject(); p.setScm(scm); p.setAssignedLabel(r.createSlave().getSelfLabel()); r.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); // should not find any change (pinned externals should be skipped on poll) // fail if it checks the revision of external URL larger than the pinned revision assertFalse(p.poll(StreamTaskListener.fromStdout()).hasChanges()); }