Search in sources :

Example 1 with Launcher

use of hudson.Launcher in project support-core-plugin by jenkinsci.

the class SlaveCommandStatisticsTest method smokes.

@Test
public void smokes() throws Exception {
    DumbSlave s = r.createSlave();
    FreeStyleProject p = r.createFreeStyleProject();
    p.setAssignedNode(s);
    p.getBuildersList().add(new TestBuilder() {

        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            build.getWorkspace().act(new SampleCallable());
            return true;
        }
    });
    r.buildAndAssertSuccess(p);
    String dump = SupportTestUtils.invokeComponentToString(ExtensionList.lookupSingleton(SlaveCommandStatistics.class));
    System.out.println(dump);
    assertThat(dump, containsString(SampleCallable.class.getName()));
}
Also used : BuildListener(hudson.model.BuildListener) Launcher(hudson.Launcher) IOException(java.io.IOException) DumbSlave(hudson.slaves.DumbSlave) FreeStyleProject(hudson.model.FreeStyleProject) TestBuilder(org.jvnet.hudson.test.TestBuilder) Test(org.junit.Test)

Example 2 with Launcher

use of hudson.Launcher in project artifact-manager-s3-plugin by jenkinsci.

the class JCloudsArtifactManagerTest method artifactBrowsingPerformance.

@Test
public void artifactBrowsingPerformance() throws Exception {
    ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(getArtifactManagerFactory());
    FreeStyleProject p = j.createFreeStyleProject();
    p.getBuildersList().add(new TestBuilder() {

        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            FilePath ws = build.getWorkspace();
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    ws.child(i + "/" + j + "/f").write(i + "-" + j, null);
                }
            }
            return true;
        }
    });
    p.getPublishersList().add(new ArtifactArchiver("**"));
    FreeStyleBuild b = j.buildAndAssertSuccess(p);
    httpLogging.record(InvokeHttpMethod.class, Level.FINE);
    httpLogging.capture(1000);
    JenkinsRule.WebClient wc = j.createWebClient();
    // Exercise DirectoryBrowserSupport & Run.getArtifactsUpTo
    System.err.println("build root");
    wc.getPage(b);
    System.err.println("artifact root");
    wc.getPage(b, "artifact/");
    System.err.println("3 subdir");
    wc.getPage(b, "artifact/3/");
    System.err.println("3/4 subdir");
    wc.getPage(b, "artifact/3/4/");
    int httpCount = httpLogging.getRecords().size();
    System.err.println("total count: " + httpCount);
    assertThat(httpCount, lessThanOrEqualTo(11));
}
Also used : FilePath(hudson.FilePath) ArtifactArchiver(hudson.tasks.ArtifactArchiver) IOException(java.io.IOException) FreeStyleBuild(hudson.model.FreeStyleBuild) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) TestBuilder(org.jvnet.hudson.test.TestBuilder) BuildListener(hudson.model.BuildListener) Launcher(hudson.Launcher) ArtifactManagerTest(org.jenkinsci.plugins.workflow.ArtifactManagerTest) Test(org.junit.Test)

Example 3 with Launcher

use of hudson.Launcher in project artifact-manager-s3-plugin by jenkinsci.

the class JCloudsArtifactManagerTest method archiveSingleLargeFile.

// @Test
public void archiveSingleLargeFile() throws Exception {
    ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(getArtifactManagerFactory());
    FreeStyleProject p = j.createFreeStyleProject();
    p.getBuildersList().add(new TestBuilder() {

        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            FilePath target = build.getWorkspace().child("out");
            long length = 2L * 1024 * 1024 * 1024;
            final FilePath src = new FilePath(Which.jarFile(Jenkins.class));
            final OutputStream out = target.write();
            try {
                do {
                    IOUtils.copy(src.read(), out);
                } while (target.length() < length);
            } finally {
                out.close();
            }
            return true;
        }
    });
    p.getPublishersList().add(new ArtifactArchiver("**/*"));
    FreeStyleBuild build = j.buildAndAssertSuccess(p);
    InputStream out = build.getArtifactManager().root().child("out").open();
    try {
        IOUtils.copy(out, new NullOutputStream());
    } finally {
        out.close();
    }
}
Also used : FilePath(hudson.FilePath) ArtifactArchiver(hudson.tasks.ArtifactArchiver) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) NullOutputStream(org.apache.commons.io.output.NullOutputStream) IOException(java.io.IOException) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) TestBuilder(org.jvnet.hudson.test.TestBuilder) BuildListener(hudson.model.BuildListener) Launcher(hudson.Launcher) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

Example 4 with Launcher

use of hudson.Launcher in project jenkin-qtest-plugin by QASymphony.

the class PatternScanParser method parse.

/**
 * Read test results with test result location pattern
 *
 * @param request            request
 * @param testResultLocation testResultLocation
 * @return a list of {@link AutomationTestResult}
 * @throws Exception Exception
 */
public List<AutomationTestResult> parse(ParseRequest request, String testResultLocation) throws Exception {
    JUnitParser jUnitParser = new JUnitParser(true);
    Run<?, ?> build = request.getBuild();
    Launcher launcher = request.getLauncher();
    TaskListener listener = request.getListener();
    List<TestResult> testResults = new ArrayList<>();
    testResults.add(jUnitParser.parseResult(testResultLocation, build, request.getWorkSpace(), launcher, listener));
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTimeInMillis(build.getStartTimeInMillis());
    return CommonParsingUtils.toAutomationTestResults(request, testResults, gregorianCalendar.getTime());
}
Also used : TaskListener(hudson.model.TaskListener) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) JUnitParser(hudson.tasks.junit.JUnitParser) Launcher(hudson.Launcher) TestResult(hudson.tasks.junit.TestResult) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult)

Example 5 with Launcher

use of hudson.Launcher in project workflow-job-plugin by jenkinsci.

the class WorkflowJob method poll.

@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "TODO 1.653+ switch to Jenkins.getInstanceOrNull")
@Override
public PollingResult poll(TaskListener listener) {
    if (!isBuildable()) {
        listener.getLogger().println("Build disabled");
        return PollingResult.NO_CHANGES;
    }
    // TODO 2.11+ call SCMDecisionHandler
    // TODO call SCMPollListener
    WorkflowRun lastBuild = getLastBuild();
    if (lastBuild == null) {
        listener.getLogger().println("no previous build to compare to");
        // Note that we have no equivalent of AbstractProject.NoSCM because without an initial build we do not know if this project has any SCM at all.
        return Queue.getInstance().contains(this) ? PollingResult.NO_CHANGES : PollingResult.BUILD_NOW;
    }
    WorkflowRun perhapsCompleteBuild = getLastSuccessfulBuild();
    if (perhapsCompleteBuild == null) {
        perhapsCompleteBuild = lastBuild;
    }
    if (pollingBaselines == null) {
        pollingBaselines = new ConcurrentHashMap<>();
    }
    PollingResult result = PollingResult.NO_CHANGES;
    for (WorkflowRun.SCMCheckout co : perhapsCompleteBuild.checkouts(listener)) {
        if (!co.scm.supportsPolling()) {
            listener.getLogger().println("polling not supported from " + co.workspace + " on " + co.node);
            continue;
        }
        String key = co.scm.getKey();
        SCMRevisionState pollingBaseline = pollingBaselines.get(key);
        if (pollingBaseline == null) {
            // after a restart, transient cache will be empty
            pollingBaseline = co.pollingBaseline;
        }
        if (pollingBaseline == null) {
            listener.getLogger().println("no polling baseline in " + co.workspace + " on " + co.node);
            continue;
        }
        try {
            FilePath workspace;
            Launcher launcher;
            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;
                launcher = null;
                lease = null;
            }
            PollingResult r;
            try {
                r = co.scm.compareRemoteRevisionWith(this, launcher, workspace, listener, pollingBaseline);
                if (r.remote != null) {
                    pollingBaselines.put(key, r.remote);
                }
            } finally {
                if (lease != null) {
                    lease.release();
                }
            }
            if (r.change.compareTo(result.change) > 0) {
                // note that if we are using >1 checkout, we can clobber baseline/remote here; anyway SCMTrigger only calls hasChanges()
                result = r;
            }
        } catch (AbortException x) {
            listener.error("polling failed in " + co.workspace + " on " + co.node + ": " + x.getMessage());
        } catch (Exception x) {
            // TODO 2.43+ use Functions.printStackTrace
            listener.error("polling failed in " + co.workspace + " on " + co.node).println(Functions.printThrowable(x).trim());
        }
    }
    return result;
}
Also used : FilePath(hudson.FilePath) WorkspaceList(hudson.slaves.WorkspaceList) ServletException(javax.servlet.ServletException) AbortException(hudson.AbortException) IOException(java.io.IOException) Jenkins(jenkins.model.Jenkins) SCMRevisionState(hudson.scm.SCMRevisionState) PollingResult(hudson.scm.PollingResult) Computer(hudson.model.Computer) Launcher(hudson.Launcher) AbortException(hudson.AbortException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Launcher (hudson.Launcher)19 IOException (java.io.IOException)16 FilePath (hudson.FilePath)14 Test (org.junit.Test)11 TestBuilder (org.jvnet.hudson.test.TestBuilder)10 File (java.io.File)8 FreeStyleProject (hudson.model.FreeStyleProject)6 ArrayList (java.util.ArrayList)6 BuildListener (hudson.model.BuildListener)4 EnvVars (hudson.EnvVars)3 FreeStyleBuild (hudson.model.FreeStyleBuild)3 TaskListener (hudson.model.TaskListener)3 ArtifactArchiver (hudson.tasks.ArtifactArchiver)3 AbortException (hudson.AbortException)2 PollingResult (hudson.scm.PollingResult)2 SCMRevisionState (hudson.scm.SCMRevisionState)2 WorkspaceList (hudson.slaves.WorkspaceList)2 Verifier (jenkins.plugins.nodejs.CIBuilderHelper.Verifier)2 DetectionFailedException (jenkins.plugins.nodejs.tools.DetectionFailedException)2 NodeJSInstallation (jenkins.plugins.nodejs.tools.NodeJSInstallation)2