类hudson.model.FreeStyleBuild源码实例Demo

下面列出了怎么用hudson.model.FreeStyleBuild的API类实例代码及写法,或者点击链接到github查看源代码。

private void testWithContent(String content, String len) throws Exception {
    final String fileName = "just-a-test.txt";
    project.getBuildersList().add(echoBuilder(fileName, content));
    FreeStyleBuild build = getBuild();

    RemoteFileFetcher fetcher = new RemoteFileFetcher(
            build.getWorkspace(),
            logger,
            fileName,
            len
    );

    assertEquals(content, fetcher.getRemoteFile());

    fetcher = new RemoteFileFetcher(
            build.getWorkspace(),
            logger,
            "*.txt",
            len
    );

    assertEquals(content, fetcher.getRemoteFile());
}
 
源代码2 项目: appcenter-plugin   文件: ProxyTest.java
@Test
public void should_SendProxyAuthorizationHeader_When_ProxyCredentialsConfigured() throws Exception {
    // Given
    final String userName = "user";
    final String password = "password";
    jenkinsRule.jenkins.proxy = new ProxyConfiguration(proxyWebServer.getHostName(), proxyWebServer.getPort(), userName, password);

    MockWebServerUtil.enqueueProxyAuthRequired(proxyWebServer); // first request rejected and proxy authentication requested
    MockWebServerUtil.enqueueSuccess(proxyWebServer);

    // When
    final FreeStyleBuild freeStyleBuild = freeStyleProject.scheduleBuild2(0).get();

    // Then
    jenkinsRule.assertBuildStatus(Result.SUCCESS, freeStyleBuild);
    assertThat(proxyWebServer.getRequestCount()).isEqualTo(5);
    assertThat(mockWebServer.getRequestCount()).isEqualTo(0);
    // proxy auth is performed on second request
    assertThat(proxyWebServer.takeRequest().getHeader(HttpHeaders.PROXY_AUTHORIZATION)).isNull();
    assertThat(proxyWebServer.takeRequest().getHeader(HttpHeaders.PROXY_AUTHORIZATION)).isEqualTo(Credentials.basic(userName, password));
}
 
private BuildResultProcessor runProcessLintViolationsTest(String lintFileContent, ConduitAPIClient conduitAPIClient)
        throws Exception {
    final String fileName = ".phabricator-lint";
    project.getBuildersList().add(echoBuilder(fileName, lintFileContent));
    FreeStyleBuild build = getBuild();

    BuildResultProcessor processor = new BuildResultProcessor(
            TestUtils.getDefaultLogger(),
            build,
            build.getWorkspace(),
            mock(Differential.class),
            new DifferentialClient(null, conduitAPIClient),
            TestUtils.TEST_PHID,
            mock(CodeCoverageMetrics.class),
            TestUtils.TEST_BASE_URL,
            true,
            new CoverageCheckSettings(true, 0.0, 100.0)
    );
    processor.processLintResults(fileName, "1000");
    processor.processHarbormaster();
    return processor;
}
 
@Test
public void test_readResolve() throws Exception {
    FreeStyleProject p = rule.createFreeStyleProject("test");
    FreeStyleBuild b = rule.assertBuildStatusSuccess(p.scheduleBuild2(0));
    
    ContainerRecord r1 = new ContainerRecord("192.168.1.10", "cid", IMAGE_ID, "magic", System.currentTimeMillis(), Collections.<String, String>emptyMap());
    DockerFingerprints.addRunFacet(r1, b);

    Fingerprint fingerprint = DockerFingerprints.of(IMAGE_ID);
    DockerRunFingerprintFacet facet = new DockerRunFingerprintFacet(fingerprint, System.currentTimeMillis(), IMAGE_ID);
    ContainerRecord r2 = new ContainerRecord("192.168.1.10", "cid", null, "magic", System.currentTimeMillis(), Collections.<String, String>emptyMap());
    facet.add(r2);
    
    Assert.assertNull(r2.getImageId());
    facet.readResolve();
    Assert.assertEquals(IMAGE_ID, r2.getImageId());
    
    // Check that actions have been automatically added
    DockerFingerprintAction fpAction = b.getAction(DockerFingerprintAction.class);
    Assert.assertNotNull("DockerFingerprintAction should be added automatically", fpAction);
    Assert.assertTrue("Docker image should be referred in the action", 
            fpAction.getImageIDs().contains(IMAGE_ID));
}
 
@Test
public void testPostUnitWithFailure() throws Exception {
    TestUtils.addCopyBuildStep(p, TestUtils.JUNIT_XML, JUnitTestProvider.class, "go-torch-junit-fail.xml");
    p.getPublishersList().add(TestUtils.getDefaultXUnitPublisher());

    FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject());
    assertEquals(Result.UNSTABLE, build.getResult());
    assertLogContains("Publishing unit results to Harbormaster for 8 tests", build);

    FakeConduit conduitTestClient = getConduitClient();
    // There are two requests, first it fetches the diff info, secondly it posts the unit result to harbormaster
    assertEquals(2, conduitTestClient.getRequestBodies().size());
    String actualUnitResultWithFailureRequestBody = conduitTestClient.getRequestBodies().get(1);

    assertConduitRequest(getUnitResultWithFailureRequest(), actualUnitResultWithFailureRequestBody);
}
 
源代码6 项目: appcenter-plugin   文件: EnvInterpolationTest.java
@Test
public void should_InterpolateEnv_InDestinationGroups() throws Exception {
    // Given
    MockWebServerUtil.enqueueSuccessWithSymbols(mockWebServer);

    // When
    final FreeStyleBuild freeStyleBuild = freeStyleProject.scheduleBuild2(0).get();

    // Then
    jenkinsRule.assertBuildStatus(Result.SUCCESS, freeStyleBuild);
    mockWebServer.takeRequest();
    mockWebServer.takeRequest();
    mockWebServer.takeRequest();
    mockWebServer.takeRequest();
    mockWebServer.takeRequest();
    mockWebServer.takeRequest();
    final RecordedRequest recordedRequest = mockWebServer.takeRequest();
    assertThat(recordedRequest.getBody().readUtf8()).contains("[{\"name\":\"casey\"},{\"name\":\"niccoli\"}]");
}
 
源代码7 项目: warnings-ng-plugin   文件: DockerContainerITest.java
/**
 * Runs a make file to compile a cpp file on a docker container agent.
 *
 * @throws IOException
 *         When the node assignment of the agent fails.
 * @throws InterruptedException
 *         If the creation of the docker container fails.
 */
@Test
public void shouldBuildMakefileOnAgent() throws IOException, InterruptedException {
    assumeThat(isWindows()).as("Running on Windows").isFalse();

    DumbSlave agent = createDockerContainerAgent(gccDockerRule.get());

    FreeStyleProject project = createFreeStyleProject();
    project.setAssignedNode(agent);

    createFileInAgentWorkspace(agent, project, "test.cpp", getSampleCppFile());
    createFileInAgentWorkspace(agent, project, "makefile", getSampleMakefileFile());
    project.getBuildersList().add(new Shell("make"));
    enableWarnings(project, createTool(new Gcc4(), ""));

    scheduleSuccessfulBuild(project);

    FreeStyleBuild lastBuild = project.getLastBuild();
    AnalysisResult result = getAnalysisResult(lastBuild);

    assertThat(result).hasTotalSize(1);
    assertThat(lastBuild.getBuiltOn().getLabelString()).isEqualTo(((Node) agent).getLabelString());
}
 
源代码8 项目: junit-plugin   文件: JUnitResultArchiverTest.java
private void assertTestResults(FreeStyleBuild build) {
    TestResultAction testResultAction = build.getAction(TestResultAction.class);
    assertNotNull("no TestResultAction", testResultAction);

    TestResult result = testResultAction.getResult();
    assertNotNull("no TestResult", result);

    assertEquals("should have 1 failing test", 1, testResultAction.getFailCount());
    assertEquals("should have 1 failing test", 1, result.getFailCount());

    assertEquals("should have 132 total tests", 132, testResultAction.getTotalCount());
    assertEquals("should have 132 total tests", 132, result.getTotalCount());

    for (SuiteResult suite : result.getSuites()) {
        assertNull("No nodeId should be present on the SuiteResult", suite.getNodeId());
    }
}
 
@Test public void basics() throws Exception {
    String username = "bob";
    String password = "s3cr3t";
    UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, null, "sample", username, password);
    CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
    FreeStyleProject p = r.createFreeStyleProject();
    p.getBuildWrappersList().add(new SecretBuildWrapper(Collections.<Binding<?>>singletonList(new UsernamePasswordBinding("AUTH", c.getId()))));
    p.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %AUTH% > auth.txt") : new Shell("echo $AUTH > auth.txt"));
    r.configRoundtrip(p);
    SecretBuildWrapper wrapper = p.getBuildWrappersList().get(SecretBuildWrapper.class);
    assertNotNull(wrapper);
    List<? extends MultiBinding<?>> bindings = wrapper.getBindings();
    assertEquals(1, bindings.size());
    MultiBinding<?> binding = bindings.get(0);
    assertEquals(c.getId(), binding.getCredentialsId());
    assertEquals(UsernamePasswordBinding.class, binding.getClass());
    assertEquals("AUTH", ((UsernamePasswordBinding) binding).getVariable());
    FreeStyleBuild b = r.buildAndAssertSuccess(p);
    r.assertLogNotContains(password, b);
    assertEquals(username + ':' + password, b.getWorkspace().child("auth.txt").readToString().trim());
    assertEquals("[AUTH]", b.getSensitiveBuildVariables().toString());
}
 
源代码10 项目: blueocean-plugin   文件: PipelineApiTest.java
@Test
public void getPipelinesTest() throws Exception {

    Project p2 = j.createFreeStyleProject("pipeline2");
    Project p1 = j.createFreeStyleProject("pipeline1");

    List<Map> responses = get("/search/?q=type:pipeline", List.class);
    assertEquals(2, responses.size());
    validatePipeline(p1, responses.get(0));
    validatePipeline(p2, responses.get(1));

    p1.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    FreeStyleBuild b = (FreeStyleBuild) p1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b);


}
 
源代码11 项目: blueocean-plugin   文件: PipelineApiTest.java
@Test
public void getFreeStyleJobTest() throws Exception {
    Project p1 = j.createFreeStyleProject("pipeline1");
    Project p2 = j.createFreeStyleProject("pipeline2");
    p1.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    FreeStyleBuild b = (FreeStyleBuild) p1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b);

    List<Map> resp = get("/organizations/jenkins/pipelines/", List.class);
    Project[] projects = {p1,p2};

    assertEquals(projects.length, resp.size());

    for(int i=0; i<projects.length; i++){
        Map p = resp.get(i);
        validatePipeline(projects[i], p);
    }
}
 
源代码12 项目: blueocean-plugin   文件: PipelineApiTest.java
@Test
public void getPipelineRunWithTestResult() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pipeline4");
    p.getBuildersList().add(new Shell("echo '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<testsuite xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd\" name=\"io.jenkins.blueocean.jsextensions.JenkinsJSExtensionsTest\" time=\"35.7\" tests=\"1\" errors=\"0\" skipped=\"0\" failures=\"0\">\n" +
        "  <properties>\n" +
        "  </properties>\n" +
        "  <testcase name=\"test\" classname=\"io.jenkins.blueocean.jsextensions.JenkinsJSExtensionsTest\" time=\"34.09\"/>\n" +
        "</testsuite>' > test-result.xml"));

    p.getPublishersList().add(new JUnitResultArchiver("*.xml"));
    FreeStyleBuild b = p.scheduleBuild2(0).get();
    TestResultAction resultAction = b.getAction(TestResultAction.class);
    assertEquals("io.jenkins.blueocean.jsextensions.JenkinsJSExtensionsTest",resultAction.getResult().getSuites().iterator().next().getName());
    j.assertBuildStatusSuccess(b);
    Map resp = get("/organizations/jenkins/pipelines/pipeline4/runs/"+b.getId());

    //discover TestResultAction super classes
    get("/classes/hudson.tasks.junit.TestResultAction/");

    // get junit rest report
    get("/organizations/jenkins/pipelines/pipeline4/runs/"+b.getId()+"/testReport/result/");
}
 
源代码13 项目: blueocean-plugin   文件: PipelineApiTest.java
@Test
public void getPipelineRunLatestTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pipeline5");
    p.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    FreeStyleBuild b = p.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b);

    List<Map> resp = get("/search?q=type:run;organization:jenkins;pipeline:pipeline5;latestOnly:true", List.class);
    Run[] run = {b};

    assertEquals(run.length, resp.size());

    for(int i=0; i<run.length; i++){
        Map lr = resp.get(i);
        validateRun(run[i], lr);
    }
}
 
@Test
public void given_jobOrRun_then_differentURLs() throws Exception {
    List<GitHubSCMSource> srcs = Arrays.asList(
            new GitHubSCMSource("example", "test", null, false),
            new GitHubSCMSource("", "", "http://github.com/example/test", true)
    );
    for( GitHubSCMSource src: srcs) {
        FreeStyleProject job = j.createFreeStyleProject();
        FreeStyleBuild run = j.buildAndAssertSuccess(job);
        DefaultGitHubNotificationStrategy instance = new DefaultGitHubNotificationStrategy();
        String urlA = instance.notifications(GitHubNotificationContext.build(null, run, src, new BranchSCMHead("master")),
                new LogTaskListener(Logger.getLogger(getClass().getName()), Level.INFO)).get(0).getUrl();
        String urlB = instance.notifications(GitHubNotificationContext.build(job, null, src, new BranchSCMHead("master")),
                new LogTaskListener(Logger.getLogger(getClass().getName()), Level.INFO)).get(0).getUrl();
        assertNotEquals(urlA, urlB);
    }
}
 
源代码15 项目: blueocean-plugin   文件: PipelineApiTest.java
@Test
public void findPipelineRunsForAPipelineTest() throws Exception {
    FreeStyleProject p1 = j.createFreeStyleProject("pipeline1");
    FreeStyleProject p2 = j.createFreeStyleProject("pipeline2");
    p1.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    p2.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    Stack<FreeStyleBuild> builds = new Stack<FreeStyleBuild>();
    FreeStyleBuild b11 = p1.scheduleBuild2(0).get();
    FreeStyleBuild b12 = p1.scheduleBuild2(0).get();
    builds.push(b11);
    builds.push(b12);

    j.assertBuildStatusSuccess(b11);
    j.assertBuildStatusSuccess(b12);

    List<Map> resp = get("/search?q=type:run;organization:jenkins;pipeline:pipeline1", List.class);

    assertEquals(builds.size(), resp.size());
    for(int i=0; i< builds.size(); i++){
        Map p = resp.get(i);
        FreeStyleBuild b = builds.pop();
        validateRun(b, p);
    }
}
 
源代码16 项目: blueocean-plugin   文件: PipelineApiTest.java
@Test
public void findAllPipelineTest() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    j.createFolder("afolder");
    Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
    folder1.createProject(MockFolder.class, "folder3");
    folder2.createProject(FreeStyleProject.class, "test2");

    FreeStyleBuild b1 = (FreeStyleBuild) p1.scheduleBuild2(0).get();


    List<Map> resp = get("/search?q=type:pipeline", List.class);

    assertEquals(6, resp.size());
}
 
源代码17 项目: blueocean-plugin   文件: PipelineApiTest.java
@Test
public void findPipelineRunsForAllPipelineTest() throws IOException, ExecutionException, InterruptedException {
    FreeStyleProject p1 = j.createFreeStyleProject("pipeline11");
    FreeStyleProject p2 = j.createFreeStyleProject("pipeline22");
    p1.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    p2.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    Stack<FreeStyleBuild> p1builds = new Stack<FreeStyleBuild>();
    p1builds.push(p1.scheduleBuild2(0).get());
    p1builds.push(p1.scheduleBuild2(0).get());

    Stack<FreeStyleBuild> p2builds = new Stack<FreeStyleBuild>();
    p2builds.push(p2.scheduleBuild2(0).get());
    p2builds.push(p2.scheduleBuild2(0).get());

    Map<String, Stack<FreeStyleBuild>> buildMap = ImmutableMap.of(p1.getName(), p1builds, p2.getName(), p2builds);

    List<Map> resp = get("/search?q=type:run;organization:jenkins", List.class);

    assertEquals(4, resp.size());
    for(int i=0; i< 4; i++){
        Map p = resp.get(i);
        String pipeline = (String) p.get("pipeline");
        assertNotNull(pipeline);
        validateRun(buildMap.get(pipeline).pop(), p);
    }
}
 
@Test
public void testPassBuildOnDecreasedCoverageButGreaterThanMinPercent() throws Exception {
    TestUtils.addCopyBuildStep(p, TestUtils.COBERTURA_XML, XmlCoverageProvider.class, "go-torch-coverage2.xml");
    UberallsClient uberalls = TestUtils.getDefaultUberallsClient();
    notifier = getNotifierWithCoverageCheck(0.0, 90.0);

    when(uberalls.getCoverage(any(String.class))).thenReturn("{\n" +
            "  \"sha\": \"deadbeef\",\n" +
            "  \"lineCoverage\": 100,\n" +
            "  \"filesCoverage\": 100,\n" +
            "  \"packageCoverage\": 100,\n" +
            "  \"classesCoverage\": 100,\n" +
            "  \"methodCoverage\": 100,\n" +
            "  \"conditionalCoverage\": 100,\n" +
            "  \"linesCovered\": 100,\n" +
            "  \"linesTested\": 100\n" +
            "}");
    notifier.getDescriptor().setUberallsURL("http://uber.alls");
    notifier.setUberallsClient(uberalls);

    FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject());
    assertEquals(Result.SUCCESS, build.getResult());
}
 
源代码19 项目: blueocean-plugin   文件: StatePreloaderTest.java
@Test
public void test() throws IOException, ExecutionException, InterruptedException, SAXException {
    // Create a project and run a build on it.
    FreeStyleProject freestyleProject = j.createProject(FreeStyleProject.class, "freestyle");
    FreeStyleBuild run = freestyleProject.scheduleBuild2(0).get();
    j.waitForCompletion(run);

    // Lets request the activity page for that project. The page should
    // contain some prefetched javascript for the pipeline
    // details + the runs on the page
    Assert.assertTrue(BlueOceanUrlMapper.all().size()> 0);
    BlueOceanUrlMapper mapper = BlueOceanUrlMapper.all().get(0);
    String projectBlueUrl = j.jenkins.getRootUrl() + mapper.getUrl(freestyleProject);
    Document doc = Jsoup.connect(projectBlueUrl + "/activity/").get();
    String script = doc.select("head script").toString();

    Assert.assertTrue(script.contains(String.format("setState('prefetchdata.%s',", PipelineStatePreloader.class.getSimpleName())));
    Assert.assertTrue(script.contains(String.format("setState('prefetchdata.%s',", PipelineActivityStatePreloader.class.getSimpleName())));
    Assert.assertTrue(script.contains("\"restUrl\":\"/blue/rest/organizations/jenkins/pipelines/freestyle/runs/?start=0&limit=26\""));
}
 
源代码20 项目: junit-plugin   文件: TestResultLinksTest.java
@LocalData
@Test
public void testNonDescendantRelativePath() throws Exception {
    FreeStyleBuild build = project.scheduleBuild2(0).get(10, TimeUnit.MINUTES); // leave time for interactive debugging
    rule.assertBuildStatus(Result.UNSTABLE, build);
    TestResult theOverallTestResult =   build.getAction(TestResultAction.class).getResult();
    CaseResult theFailedTestCase = theOverallTestResult.getFailedTests().get(0);
    String relativePath = theFailedTestCase.getRelativePathFrom(theOverallTestResult);
    System.out.println("relative path seems to be: " + relativePath);
    assertNotNull("relative path exists", relativePath);
    assertFalse("relative path doesn't start with a slash", relativePath.startsWith("/"));

    // Now ask for the relative path from the child to the parent -- we should get an absolute path
    String relativePath2 = theOverallTestResult.getRelativePathFrom(theFailedTestCase);
    System.out.println("relative path2 seems to be: " + relativePath2);
    // I know that in a HudsonTestCase we don't have a meaningful root url, so I expect an empty string here.
    // If somehow we start being able to produce a root url, then I'll also tolerate a url that starts with that.
    boolean pathIsEmptyOrNull = relativePath2 == null || relativePath2.isEmpty();
    boolean pathStartsWithRootUrl = !pathIsEmptyOrNull && relativePath2.startsWith(rule.jenkins.getRootUrl());
    assertTrue("relative path is empty OR begins with the app root", pathIsEmptyOrNull || pathStartsWithRootUrl ); 
}
 
@Test
public void testNoCommentConfigured() throws Exception {
    FreeStyleBuild build = getBuild();
    RemoteFileFetcher fetcher = new RemoteFileFetcher(
            build.getWorkspace(),
            logger,
            "",
            "1000"
    );

    assertNull(fetcher.getRemoteFile());

    fetcher = new RemoteFileFetcher(
            build.getWorkspace(),
            logger,
            "non-existent",
            "1000"
    );

    assertNull(fetcher.getRemoteFile());
}
 
@Ignore("For local experiments")
@Test
public void testWrapper() throws Exception {
    final FreeStyleProject project = jRule.createProject(FreeStyleProject.class, "freestyle");

    final DockerConnector connector = new DockerConnector("tcp://" + ADDRESS + ":2376/");
    connector.setConnectorType(JERSEY);

    final DockerSlaveConfig config = new DockerSlaveConfig();
    config.getDockerContainerLifecycle().setImage("java:8-jdk-alpine");
    config.setLauncher(new NoOpDelegatingComputerLauncher(new DockerComputerSingleJNLPLauncher()));
    config.setRetentionStrategy(new DockerOnceRetentionStrategy(10));

    final DockerSimpleBuildWrapper dockerSimpleBuildWrapper = new DockerSimpleBuildWrapper(connector, config);
    project.getBuildWrappersList().add(dockerSimpleBuildWrapper);
    project.getBuildersList().add(new Shell("sleep 30"));

    final QueueTaskFuture<FreeStyleBuild> taskFuture = project.scheduleBuild2(0);

    jRule.waitUntilNoActivity();
    jRule.pause();
}
 
protected void should_connect_agent(DockerTemplate template) throws IOException, ExecutionException, InterruptedException, TimeoutException {

        // FIXME on CI windows nodes don't have Docker4Windows
        Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);

        String dockerHost = SystemUtils.IS_OS_WINDOWS ? "tcp://localhost:2375" : "unix:///var/run/docker.sock";

        DockerCloud cloud = new DockerCloud(cloudName, new DockerAPI(new DockerServerEndpoint(dockerHost, null)),
                Collections.singletonList(template));

        j.jenkins.clouds.replaceBy(Collections.singleton(cloud));

        final FreeStyleProject project = j.createFreeStyleProject("test-docker-ssh");
        project.setAssignedLabel(Label.get(LABEL));
        project.getBuildersList().add(new Shell("whoami"));
        final QueueTaskFuture<FreeStyleBuild> scheduledBuild = project.scheduleBuild2(0);
        try {
            final FreeStyleBuild build = scheduledBuild.get(60L, TimeUnit.SECONDS);
            Assert.assertTrue(build.getResult() == Result.SUCCESS);
            Assert.assertTrue(build.getLog().contains("jenkins"));
        } finally {
            scheduledBuild.cancel(true);
        }
    }
 
源代码24 项目: appcenter-plugin   文件: ProxyTest.java
@Test
public void should_SendRequestsToProxy_When_ProxyConfigurationFound() throws Exception {
    // Given
    jenkinsRule.jenkins.proxy = new ProxyConfiguration(proxyWebServer.getHostName(), proxyWebServer.getPort());
    MockWebServerUtil.enqueueSuccess(proxyWebServer);

    // When
    final FreeStyleBuild freeStyleBuild = freeStyleProject.scheduleBuild2(0).get();

    // Then
    jenkinsRule.assertBuildStatus(Result.SUCCESS, freeStyleBuild);
    assertThat(proxyWebServer.getRequestCount()).isEqualTo(4);
    assertThat(mockWebServer.getRequestCount()).isEqualTo(0);
}
 
@Issue("JENKINS-24805")
@Test public void maskingFreeStyleSecrets() throws Exception {
    String firstCredentialsId = "creds_1";
    String firstPassword = "p4$$";
    StringCredentialsImpl firstCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, firstCredentialsId, "sample1", Secret.fromString(firstPassword));

    CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), firstCreds);

    String secondCredentialsId = "creds_2";
    String secondPassword = "p4$$" + "someMoreStuff";
    StringCredentialsImpl secondCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, secondCredentialsId, "sample2", Secret.fromString(secondPassword));

    CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), secondCreds);

    SecretBuildWrapper wrapper = new SecretBuildWrapper(Arrays.asList(new StringBinding("PASS_1", firstCredentialsId),
            new StringBinding("PASS_2", secondCredentialsId)));

    FreeStyleProject f = r.createFreeStyleProject();

    f.setConcurrentBuild(true);
    f.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_1%") : new Shell("echo \"$PASS_1\""));
    f.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_2%") : new Shell("echo \"$PASS_2\""));
    f.getBuildWrappersList().add(wrapper);

    r.configRoundtrip((Item)f);

    FreeStyleBuild b = r.buildAndAssertSuccess(f);
    r.assertLogNotContains(firstPassword, b);
    r.assertLogNotContains(secondPassword, b);
    r.assertLogContains("****", b);
}
 
源代码26 项目: appcenter-plugin   文件: EnvInterpolationTest.java
@Test
public void should_InterpolateEnv_InAppName() throws Exception {
    // Given
    MockWebServerUtil.enqueueSuccessWithSymbols(mockWebServer);

    // When
    final FreeStyleBuild freeStyleBuild = freeStyleProject.scheduleBuild2(0).get();

    // Then
    jenkinsRule.assertBuildStatus(Result.SUCCESS, freeStyleBuild);
    final RecordedRequest recordedRequest = mockWebServer.takeRequest();
    assertThat(recordedRequest.getPath()).contains("ritual-de-lo-habitual");
}
 
源代码27 项目: appcenter-plugin   文件: EnvInterpolationTest.java
@Test
public void should_InterpolateEnv_InDebugSymbolPath() throws Exception {
    // Given
    MockWebServerUtil.enqueueSuccessWithSymbols(mockWebServer);

    // When
    final FreeStyleBuild freeStyleBuild = freeStyleProject.scheduleBuild2(0).get();

    // Then
    jenkinsRule.assertBuildStatus(Result.SUCCESS, freeStyleBuild);
    mockWebServer.takeRequest();
    final RecordedRequest recordedRequest = mockWebServer.takeRequest();
    assertThat(recordedRequest.getBody().readUtf8()).contains("\"symbol_type\":\"Apple\"");
}
 
源代码28 项目: appcenter-plugin   文件: FreestyleTest.java
@Test
public void should_SetBuildResultFailure_When_UploadTaskFails() throws Exception {
    // Given
    MockWebServerUtil.enqueueFailure(mockWebServer);

    // When
    final FreeStyleBuild freeStyleBuild = freeStyleProject.scheduleBuild2(0).get();

    // Then
    jenkinsRule.assertBuildStatus(Result.FAILURE, freeStyleBuild);
}
 
@Test
public void getUpstreamRunIfAvailable() throws Exception {
    FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, null, true);
    FreeStyleBuild upstream = buildWithConduit(getFetchDiffResponse(), null, null, true);
    assertNull(PhabricatorBuildWrapper.getUpstreamRun(build));

    List<Cause> causes = build.getAction(CauseAction.class).getCauses();
    ArrayList<Cause> newCauses = new ArrayList<Cause>(causes);
    newCauses.add((new Cause.UpstreamCause(upstream)));
    build.replaceAction(new CauseAction(newCauses));

    assertEquals(upstream, PhabricatorBuildWrapper.getUpstreamRun(build));
}
 
源代码30 项目: junit-plugin   文件: TestResultLinksTest.java
@LocalData
@Test
public void testFailureLinks() throws Exception {
    FreeStyleBuild build = project.scheduleBuild2(0).get(10, TimeUnit.SECONDS);
    rule.assertBuildStatus(Result.UNSTABLE, build);

    TestResult theOverallTestResult =   build.getAction(TestResultAction.class).getResult();
    CaseResult theFailedTestCase = theOverallTestResult.getFailedTests().get(0);
    String relativePath = theFailedTestCase.getRelativePathFrom(theOverallTestResult);
    System.out.println("relative path seems to be: " + relativePath); 

    WebClient wc = rule.createWebClient();

    String testReportPageUrl =  project.getLastBuild().getUrl() + "/testReport";
    HtmlPage testReportPage = wc.goTo( testReportPageUrl );

    Page packagePage = testReportPage.getAnchorByText("tacoshack.meals").click();
    rule.assertGoodStatus(packagePage); // I expect this to work; just checking that my use of the APIs is correct.

    // Now we're on that page. We should be able to find a link to the failed test in there.
    HtmlAnchor anchor = testReportPage.getAnchorByText("tacoshack.meals.NachosTest.testBeanDip");
    String href = anchor.getHrefAttribute();
    System.out.println("link is : " + href);
    Page failureFromLink = anchor.click();
    rule.assertGoodStatus(failureFromLink);

    // Now check the >>> link -- this is harder, because we can't do the javascript click handler properly
    // The summary page is just tack on /summary to the url for the test

}
 
 类所在包
 类方法
 同包方法