jenkins.branch.BranchProperty Java Examples

The following examples show how to use jenkins.branch.BranchProperty. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TemplateDrivenBranchProjectFactory.java    From multi-branch-project-plugin with MIT License 6 votes vote down vote up
@Nonnull
@Override
public Branch getBranch(@Nonnull P project) {
    BranchProjectProperty property = project.getProperty(BranchProjectProperty.class);

    /*
     * Ugly hackish stuff, in the event that the user configures a branch project directly, thereby removing the
     * BranchProjectProperty.  The property must exist and we can't bash the @Nonnull return value restriction!
     *
     * Fudge some generic Branch with the expectation that indexing will soon reset the Branch with proper values,
     * or that it will be converted to Branch.Dead and the guessed values for sourceId and properties won't matter.
     */
    if (property == null) {
        Branch branch = new Branch("unknown", new SCMHead(project.getDisplayName()), project.getScm(),
                Collections.<BranchProperty>emptyList());
        setBranch(project, branch);
        return branch;
    }

    return property.getBranch();
}
 
Example #2
Source File: DefaultsBinderTest.java    From pipeline-multibranch-defaults-plugin with MIT License 6 votes vote down vote up
@Test
public void testDefaultJenkinsFileLoadFromWorkspace() throws Exception {
    GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
    ConfigFileStore store = globalConfigFiles.get();
    Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
        "semaphore 'wait'; node {checkout scm; load 'Jenkinsfile'}");
    store.save(config);


    sampleGitRepo.init();
    sampleGitRepo.write("Jenkinsfile", "echo readFile('file')");
    sampleGitRepo.git("add", "Jenkinsfile");
    sampleGitRepo.write("file", "initial content");
    sampleGitRepo.git("commit", "--all", "--message=flow");
    WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
    SemaphoreStep.waitForStart("wait/1", null);
    WorkflowRun b1 = p.getLastBuild();
    assertNotNull(b1);
    assertEquals(1, b1.getNumber());
    SemaphoreStep.success("wait/1", null);
    r.assertLogContains("initial content", r.waitForCompletion(b1));
}
 
Example #3
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void resolveMbpLink() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    FreeStyleProject f = j.jenkins.createProject(FreeStyleProject.class, "f");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();

    j.waitUntilNoActivity();

    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/",LinkResolver.resolveLink(mp).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/master/",LinkResolver.resolveLink(mp.getBranch("master")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature%252Fux-1/",LinkResolver.resolveLink(mp.getBranch("feature%2Fux-1")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/",LinkResolver.resolveLink(mp.getBranch("feature2")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/f/",LinkResolver.resolveLink(f).getHref());
}
 
Example #4
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void getMultiBranchPipelines() throws IOException, ExecutionException, InterruptedException {
    Assume.assumeTrue(runAllTests());
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    FreeStyleProject f = j.jenkins.createProject(FreeStyleProject.class, "f");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();

    List<Map> resp = get("/organizations/jenkins/pipelines/", List.class);
    Assert.assertEquals(2, resp.size());
    validatePipeline(f, resp.get(0));
    validateMultiBranchPipeline(mp, resp.get(1), 3);
    Assert.assertEquals(mp.getBranch("master").getBuildHealth().getScore(), resp.get(0).get("weatherScore"));
}
 
Example #5
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void getMultiBranchPipelineInsideFolder() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    WorkflowMultiBranchProject mp = folder1.createProject(WorkflowMultiBranchProject.class, "p");
    mp.setDisplayName("My MBP");

    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();

    Map r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/");

    validateMultiBranchPipeline(mp, r, 3);
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/p/",
        ((Map)((Map)r.get("_links")).get("self")).get("href"));
    Assert.assertEquals("folder1/My%20MBP", r.get("fullDisplayName"));
    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/master/");
    Assert.assertEquals("folder1/My%20MBP/master", r.get("fullDisplayName"));
}
 
Example #6
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void getPipelinesTest() throws Exception {

    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");


    j.waitUntilNoActivity();

    List<Map> responses = get("/search/?q=type:pipeline;excludedFromFlattening:jenkins.branch.MultiBranchProject", List.class);
    Assert.assertEquals(1, responses.size());
}
 
Example #7
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void getMultiBranchPipelineRunStages() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");


    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(3, mp.getItems().size());

    j.waitForCompletion(b1);

    List<Map> nodes = get("/organizations/jenkins/pipelines/p/branches/master/runs/1/nodes", List.class);

    Assert.assertEquals(3, nodes.size());
}
 
Example #8
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void getMultiBranchPipelinesWithNonMasterBranch() throws Exception {
    sampleRepo.git("checkout", "feature2");
    sampleRepo.git("branch","-D", "master");
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");

    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();

    List<Map> resp = get("/organizations/jenkins/pipelines/", List.class);
    Assert.assertEquals(1, resp.size());
    validateMultiBranchPipeline(mp, resp.get(0), 2);
    assertNull(mp.getBranch("master"));
}
 
Example #9
Source File: DefaultsBinderTest.java    From pipeline-multibranch-defaults-plugin with MIT License 6 votes vote down vote up
@Test
public void testDefaultJenkinsFile() throws Exception {
    GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
    ConfigFileStore store = globalConfigFiles.get();

    Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
        "semaphore 'wait'; node {checkout scm; echo readFile('file')}");
    store.save(config);

    sampleGitRepo.init();
    sampleGitRepo.write("file", "initial content");
    sampleGitRepo.git("commit", "--all", "--message=flow");
    WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
    SemaphoreStep.waitForStart("wait/1", null);
    WorkflowRun b1 = p.getLastBuild();
    assertNotNull(b1);
    assertEquals(1, b1.getNumber());
    SemaphoreStep.success("wait/1", null);
    r.assertLogContains("initial content", r.waitForCompletion(b1));
}
 
Example #10
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void multiBranchPipelineIndex() throws Exception {
    User user = login();
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
            new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    Map map = new RequestBuilder(baseUrl)
            .post("/organizations/jenkins/pipelines/p/runs/")
            .jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId()))
            .crumb( getCrumb( j.jenkins ) )
            .data(ImmutableMap.of())
            .status(200)
            .build(Map.class);

    assertNotNull(map);
}
 
Example #11
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void startMultiBranchPipelineRuns() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, "feature%2Fux-1");
    j.waitUntilNoActivity();

    Map resp = post("/organizations/jenkins/pipelines/p/branches/"+ Util.rawEncode("feature%2Fux-1")+"/runs/",
        Collections.EMPTY_MAP);
    String id = (String) resp.get("id");
    String link = getHrefFromLinks(resp, "self");
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature%252Fux-1/runs/"+id+"/", link);
}
 
Example #12
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void getPipelineJobRunsNoBranches() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo1.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));

    List l = request().get("/organizations/jenkins/pipelines/p/runs").build(List.class);

    Assert.assertEquals(0, l.size());

    List branches = request().get("/organizations/jenkins/pipelines/p/runs").build(List.class);
    Assert.assertEquals(0, branches.size());

}
 
Example #13
Source File: BlueOceanWebURLBuilderTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void getMultiBranchPipelineInsideFolder() throws Exception {
    MockFolder folder1 = jenkinsRule.createFolder("folder1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder two with spaces");
    WorkflowMultiBranchProject mp = folder2.createProject(WorkflowMultiBranchProject.class, "p");

    String blueOceanURL;

    blueOceanURL = urlMapper.getUrl(mp);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches/", blueOceanURL);

    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();
    jenkinsRule.waitUntilNoActivity();

    // All branch jobs should just resolve back to the same top level branches
    // page for the multibranch job in Blue Ocean.
    WorkflowJob masterJob = findBranchProject(mp, "master");
    blueOceanURL = urlMapper.getUrl(masterJob);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches/", blueOceanURL);
    WorkflowJob featureUx1Job = findBranchProject(mp, "feature/ux-1");
    blueOceanURL = urlMapper.getUrl(featureUx1Job);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches/", blueOceanURL);
    WorkflowJob feature2Job = findBranchProject(mp, "feature2");
    blueOceanURL = urlMapper.getUrl(feature2Job);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches/", blueOceanURL);

    // Runs on the jobs
    blueOceanURL = urlMapper.getUrl(masterJob.getFirstBuild());
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/detail/master/1/", blueOceanURL);
    blueOceanURL = urlMapper.getUrl(featureUx1Job.getFirstBuild());
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/detail/feature%2Fux-1/1/", blueOceanURL);
}
 
Example #14
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void getMultiBranchPipeline() throws IOException, ExecutionException, InterruptedException {
    Assume.assumeTrue(runAllTests());
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();


    Map resp = get("/organizations/jenkins/pipelines/p/");
    validateMultiBranchPipeline(mp, resp, 3);

    List<String> names = (List<String>) resp.get("branchNames");

    IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(names, branches);

    List<Map> br = get("/organizations/jenkins/pipelines/p/branches", List.class);

    List<String> branchNames = new ArrayList<>();
    List<Integer> weather = new ArrayList<>();
    for (Map b : br) {
        branchNames.add((String) b.get("name"));
        weather.add((int) b.get("weatherScore"));
    }

    for (String n : branches) {
        assertTrue(branchNames.contains(n));
    }

    for (int s : weather) {
        assertEquals(100, s);
    }
}
 
Example #15
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void testMultiBranchPipelineBranchSecurePermissions() throws IOException, ExecutionException, InterruptedException {
    j.jenkins.setSecurityRealm(new HudsonPrivateSecurityRealm(false));
    j.jenkins.setAuthorizationStrategy(new LegacyAuthorizationStrategy());

    MockFolder folder1 = j.createFolder("folder1");
    WorkflowMultiBranchProject mp = folder1.createProject(WorkflowMultiBranchProject.class, "p");

    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();


    Map r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/");


    Map<String,Boolean> permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertFalse(permissions.get("create"));
    Assert.assertTrue(permissions.get("read"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));



    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/branches/master/");

    permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertFalse(permissions.get("create"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));
    Assert.assertTrue(permissions.get("read"));
}
 
Example #16
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void testMultiBranchPipelineBranchUnsecurePermissions() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    WorkflowMultiBranchProject mp = folder1.createProject(WorkflowMultiBranchProject.class, "p");

    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();


    Map r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/");


    Map<String,Boolean> permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertTrue(permissions.get("create"));
    Assert.assertTrue(permissions.get("read"));
    Assert.assertTrue(permissions.get("start"));
    Assert.assertTrue(permissions.get("stop"));



    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/branches/master/");

    permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertTrue(permissions.get("create"));
    Assert.assertTrue(permissions.get("start"));
    Assert.assertTrue(permissions.get("stop"));
    Assert.assertTrue(permissions.get("read"));
}
 
Example #17
Source File: JobAnalyticsTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
private void createMultiBranch(GitSampleRepoRule rule) throws Exception {
    WorkflowMultiBranchProject mp = j.createProject(WorkflowMultiBranchProject.class, UUID.randomUUID().toString());
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, rule.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    mp.save();
    mp.scheduleBuild2(0).getFuture().get();
    mp.getIndexing().getLogText().writeLogTo(0, System.out);
    j.waitUntilNoActivity();
    WorkflowJob master = mp.getItemByBranchName("master");
    assertNotNull(master);
    WorkflowRun lastBuild = master.getLastBuild();
    assertNotNull(lastBuild);
    assertEquals(Result.SUCCESS, lastBuild.getResult());
}
 
Example #18
Source File: SseEventTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void multiBranchJobEventsWithCustomOrg() throws Exception {
    MockFolder folder = j.createFolder("TestOrgFolderName");
    assertNotNull(folder);

    setupScm();

    final OneShotEvent success = new OneShotEvent();

    final Boolean[] pipelineNameMatched = {null};
    final Boolean[] mbpPipelineNameMatched = {null};

    SSEConnection con = new SSEConnection(j.getURL(), "me", new ChannelSubscriber() {
        @Override
        public void onMessage(@Nonnull Message message) {
            System.out.println(message);
            if("job".equals(message.get(jenkins_channel))) {
                if ("org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject".equals(message.get(jenkins_object_type))) {
                    if("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
                        mbpPipelineNameMatched[0] = true;
                    }else{
                        mbpPipelineNameMatched[0] = false;
                    }
                } else if ("org.jenkinsci.plugins.workflow.job.WorkflowJob".equals(message.get(jenkins_object_type))) {
                    if("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
                        pipelineNameMatched[0] = true;
                    }else {
                        pipelineNameMatched[0] = false;
                    }
                }
            }
            if(pipelineNameMatched[0] != null && mbpPipelineNameMatched[0] != null){
                success.signal();
            }
        }
    });
    con.subscribe("pipeline");
    con.subscribe("job");

    final WorkflowMultiBranchProject mp = folder.createProject(WorkflowMultiBranchProject.class, "pipeline1");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
            new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    mp.scheduleBuild2(0).getFuture().get();

    WorkflowJob p = mp.getItem("master");
    if (p == null) {
        mp.getIndexing().writeWholeLogTo(System.out);
        fail("master project not found");
    }
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(2, mp.getItems().size());

    success.block(5000);
    con.close();
    if(success.isSignaled()) {
        assertTrue(pipelineNameMatched[0]);
        assertTrue(mbpPipelineNameMatched[0]);
    }
}
 
Example #19
Source File: BranchContainerImplTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void testBranchOrdering() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = User.get("alice");
    user.setFullName("Alice Cooper");
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();

    String token = getJwtToken(j.jenkins, "alice", "alice");

    new RequestBuilder(baseUrl)
        .put("/organizations/jenkins/pipelines/p/branches/feature2/favorite")
        .jwtToken(token)
        .data(ImmutableMap.of("favorite", true))
        .build(Map.class);

    new RequestBuilder(baseUrl)
        .put("/organizations/jenkins/pipelines/p/branches/feature4/favorite")
        .jwtToken(token)
        .data(ImmutableMap.of("favorite", true))
        .build(Map.class);

    List l = request().get("/organizations/jenkins/pipelines/p/branches/")
        .jwtToken(token)
        .build(List.class);

    Assert.assertEquals(4,l.size());
    Map o = (Map)l.get(1);
    Map o2 = (Map)l.get(0);

    WorkflowJob j1 = findBranchProject(mp, (String)o.get("name"));
    j.waitForCompletion(j1.getLastBuild());
    j.waitForCompletion(j1.scheduleBuild2(0).waitForStart());

    WorkflowJob j2 = findBranchProject(mp, (String)o2.get("name"));
    j.waitForCompletion(j2.getLastBuild());

    List l2 = request().get("/organizations/jenkins/pipelines/p/branches/")
        .jwtToken(token)
        .build(List.class);

    Assert.assertEquals(4,l.size());
    Map o1 = (Map)l2.get(0);
    Map o3 = (Map)l2.get(1);

    Assert.assertEquals(o2.get("name"), o1.get("name"));
}
 
Example #20
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void testMultiBranchPipelineQueueContainer() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    sampleRepo1.init();
    sampleRepo1.write("Jenkinsfile", "stage 'build'\n " + "node {echo 'Building'}\n" +
            "stage 'test'\nnode { echo 'Testing'}\n" +
            "sleep 10000 \n" +
            "stage 'deploy'\nnode { echo 'Deploying'}\n"
    );
    sampleRepo1.write("file", "initial content");
    sampleRepo1.git("add", "Jenkinsfile");
    sampleRepo1.git("commit", "--all", "--message=flow");

    //create feature branch
    sampleRepo1.git("checkout", "-b", "abc");
    sampleRepo1.write("Jenkinsfile", "echo \"branch=${env.BRANCH_NAME}\"; " + "node {" +
            "   stage ('Build'); " +
            "   echo ('Building'); " +
            "   stage ('Test'); sleep 10000; " +
            "   echo ('Testing'); " +
            "   stage ('Deploy'); " +
            "   echo ('Deploying'); " +
            "}");
    ScriptApproval.get().approveSignature("method java.lang.String toUpperCase");
    sampleRepo1.write("file", "subsequent content1");
    sampleRepo1.git("commit", "--all", "--message=tweaked1");


    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo1.toString(), "", "*", "", false),
            new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    scheduleAndFindBranchProject(mp);
    Resource r = BluePipelineFactory.resolve(mp);
    assertTrue(r instanceof MultiBranchPipelineImpl);

    for (WorkflowJob job : mp.getItems()) {
        Queue.Item item = job.getQueueItem();
        job.setConcurrentBuild(false);
        job.scheduleBuild2(0);
        job.scheduleBuild2(0);
    }
    Queue.Item[] queueItems = Jenkins.getInstance().getQueue().getItems();
    MultiBranchPipelineQueueContainer mbpQueueContainer =
            new MultiBranchPipelineQueueContainer((MultiBranchPipelineImpl) r);
    Iterator<BlueQueueItem> blueQueueItems = mbpQueueContainer.iterator(0,100);
    if (queueItems.length > 0){
        assertTrue(mbpQueueContainer.iterator().hasNext());
        assertEquals("/blue/rest/organizations/jenkins/pipelines/p/queue/", mbpQueueContainer.getLink().getHref());
        BlueQueueItem blueQueueItem = mbpQueueContainer.get(String.valueOf(queueItems[0].getId()));
        assertNotNull(blueQueueItem);
        assertTrue(blueQueueItems.hasNext());
    }
}
 
Example #21
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void createUserFavouriteMultibranchBranchTest() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = User.get("alice");
    user.setFullName("Alice Cooper");
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();

    WorkflowJob p1 = scheduleAndFindBranchProject(mp, "feature2");

    String token = getJwtToken(j.jenkins,"alice","alice");
    Map map = new RequestBuilder(baseUrl)
        .put("/organizations/jenkins/pipelines/p/branches/feature2/favorite")
        .jwtToken(token)
        .data(ImmutableMap.of("favorite", true))
        .build(Map.class);


    validatePipeline(p1, (Map) map.get("item"));

    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/favorite/", getHrefFromLinks(map, "self"));

    List l = new RequestBuilder(baseUrl)
        .get("/users/"+user.getId()+"/favorites/")
        .jwtToken(token)
        .build(List.class);

    Assert.assertEquals(1, l.size());

    Map branch = (Map)((Map)l.get(0)).get("item");

    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/favorite/", getHrefFromLinks((Map)l.get(0), "self"));

    validatePipeline(p1, branch);

    String c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);


    map = new RequestBuilder(baseUrl)
        .put(getUrlFromHref(getHrefFromLinks((Map)l.get(0), "self")))
        .jwtToken(token)
        .data(ImmutableMap.of("favorite", false))
        .build(Map.class);


    validatePipeline(p1, (Map) map.get("item"));

    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/favorite/", getHrefFromLinks(map, "self"));

    l = new RequestBuilder(baseUrl)
        .get("/users/"+user.getId()+"/favorites/")
        .jwtToken(token)
        .build(List.class);

    Assert.assertEquals(0, l.size());


    new RequestBuilder(baseUrl)
        .get("/users/"+user.getId()+"/favorites/")
        .jwtToken(getJwtToken(j.jenkins,"bob","bob"))
        .status(403)
        .build(String.class);

}
 
Example #22
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test @Ignore
public void getPipelineJobrRuns() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    sampleRepo1.init();
    sampleRepo1.write("Jenkinsfile", "stage 'build'\n "+"node {echo 'Building'}\n"+
        "stage 'test'\nnode { echo 'Testing'}\n" +
        "sleep 10000 \n"+
        "stage 'deploy'\nnode { echo 'Deploying'}\n"
    );
    sampleRepo1.write("file", "initial content");
    sampleRepo1.git("add", "Jenkinsfile");
    sampleRepo1.git("commit", "--all", "--message=flow");

    //create feature branch
    sampleRepo1.git("checkout", "-b", "abc");
    sampleRepo1.write("Jenkinsfile", "echo \"branch=${env.BRANCH_NAME}\"; "+"node {" +
        "   stage ('Build'); " +
        "   echo ('Building'); " +
        "   stage ('Test'); sleep 10000; " +
        "   echo ('Testing'); " +
        "   stage ('Deploy'); " +
        "   echo ('Deploying'); " +
        "}");
    ScriptApproval.get().approveSignature("method java.lang.String toUpperCase");
    sampleRepo1.write("file", "subsequent content1");
    sampleRepo1.git("commit", "--all", "--message=tweaked1");


    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo1.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    scheduleAndFindBranchProject(mp);

    for(WorkflowJob job : mp.getItems()) {
        Queue.Item item =  job.getQueueItem();
        if(item != null ) {
            item.getFuture().waitForStart();
        }
        job.setConcurrentBuild(false);
        job.scheduleBuild2(0);
        job.scheduleBuild2(0);
    }
    List l = request().get("/organizations/jenkins/pipelines/p/activities").build(List.class);

    Assert.assertEquals(4, l.size());
    Assert.assertEquals("io.jenkins.blueocean.service.embedded.rest.QueueItemImpl", ((Map) l.get(0)).get("_class"));
    Assert.assertEquals("io.jenkins.blueocean.rest.impl.pipeline.PipelineRunImpl", ((Map) l.get(2)).get("_class"));
}
 
Example #23
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void testMbpPagination() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
            new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    mp.scheduleBuild2(0).getFuture().get();
    this.j.waitUntilNoActivity();

    //create 6 runs
    List<WorkflowRun> launchedItems = new ArrayList<>();
    for(String branch:branches) {
        WorkflowJob job = findBranchProject(mp, branch);
        launchedItems.addAll(job.getBuilds());
        for (int j = 0; j < 2; j++) {
            launchedItems.add(job.scheduleBuild2(0).waitForStart());
            this.j.waitUntilNoActivity();
        }
    }

    //total 9. 3 triggered from indexing and 6 we launched
    assertEquals(9, launchedItems.size());

    //sort runs
    Collections.sort(launchedItems, new Comparator<WorkflowRun>() {
        @Override
        public int compare(WorkflowRun o1, WorkflowRun o2) {
            return new Date(o2.getStartTimeInMillis()).compareTo(new Date(o1.getStartTimeInMillis()));

        }
    });

    //request 10 runs, but should not return 9 runs.
    List<Map> resp = get("/organizations/jenkins/pipelines/p/runs?start=0&limit=10", List.class);

    assertEquals(9, resp.size()); //max number of runs are 9

    for(int i=0; i< 9; i++){
        Assert.assertEquals(launchedItems.get(i).getId(), (resp.get(i).get("id")));
    }

    // now call 3 out of 9 runs and see pagination returns only 3 and in right sort order
    resp = get("/organizations/jenkins/pipelines/p/runs?start=0&limit=3", List.class);

    assertEquals(3, resp.size());

    for(int i=0; i< 3; i++){
        Assert.assertEquals(launchedItems.get(i).getId(), (resp.get(i).get("id")));
    }
}
 
Example #24
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void branchCapabilityTest() throws Exception {

    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }

    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");


    j.waitUntilNoActivity();

    //check MBP capabilities
    Map<String,Object> response = get("/organizations/jenkins/pipelines/p/");
    String clazz = (String) response.get("_class");

    response = get("/classes/"+clazz+"/");
    Assert.assertNotNull(response);

    List<String> classes = (List<String>) response.get("classes");
    Assert.assertTrue(classes.contains(BLUE_SCM)
            && classes.contains(JENKINS_MULTI_BRANCH_PROJECT)
            && classes.contains(BLUE_MULTI_BRANCH_PIPELINE)
            && classes.contains(BLUE_PIPELINE_FOLDER)
            && classes.contains(JENKINS_ABSTRACT_FOLDER)
            && classes.contains(BLUE_PIPELINE));

    response = get("/organizations/jenkins/pipelines/p/branches/master/", Map.class);
    clazz = (String) response.get("_class");

    response = get("/classes/"+clazz+"/");
    Assert.assertNotNull(response);

    classes = (List<String>) response.get("classes");
    Assert.assertTrue(classes.contains(JENKINS_JOB)
        && classes.contains(JENKINS_WORKFLOW_JOB)
        && classes.contains(BLUE_BRANCH)
        && classes.contains(BLUE_PIPELINE)
        && classes.contains(PULL_REQUEST));
}
 
Example #25
Source File: PRUpdateGHEventSubscriber.java    From github-pr-comment-build-plugin with MIT License 4 votes vote down vote up
/**
 * Handles updates of pull requests.
 * @param event only PULL_REQUEST events
 * @param payload payload of gh-event. Never blank
 */
@Override
protected void onEvent(GHEvent event, String payload) {
    JSONObject json = JSONObject.fromObject(payload);

    // Since we receive both pull request and issue comment events in this same code,
    //  we check first which one it is and set values from different fields
    JSONObject pullRequest = json.getJSONObject("pull_request");
    final String pullRequestUrl = pullRequest.getString("html_url");
    Integer pullRequestId = pullRequest.getInt("number");

    // Make sure the action is edited
    String action = json.getString("action");
    if (!ACTION_EDITED.equals(action)) {
        LOGGER.log(Level.FINER, "Pull request action is not edited ({0}) for PR {1}, ignoring",
                new Object[] { action, pullRequestUrl }
        );
        return;
    }

    // Set some values used below
    final Pattern pullRequestJobNamePattern = Pattern.compile("^PR-" + pullRequestId + "\\b.*$",
            Pattern.CASE_INSENSITIVE);

    // Make sure the repository URL is valid
    String repoUrl = json.getJSONObject("repository").getString("html_url");
    Matcher matcher = REPOSITORY_NAME_PATTERN.matcher(repoUrl);
    if (!matcher.matches()) {
        LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl);
        return;
    }
    final GitHubRepositoryName changedRepository = GitHubRepositoryName.create(repoUrl);
    if (changedRepository == null) {
        LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl);
        return;
    }

    LOGGER.log(Level.FINE, "Received update on PR {1} for {2}", new Object[] { pullRequestId, repoUrl });
    ACL.impersonate(ACL.SYSTEM, new Runnable() {
        @Override
        public void run() {
            boolean jobFound = false;
            for (final SCMSourceOwner owner : SCMSourceOwners.all()) {
                for (SCMSource source : owner.getSCMSources()) {
                    if (!(source instanceof GitHubSCMSource)) {
                        continue;
                    }
                    GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
                    if (gitHubSCMSource.getRepoOwner().equalsIgnoreCase(changedRepository.getUserName()) &&
                            gitHubSCMSource.getRepository().equalsIgnoreCase(changedRepository.getRepositoryName())) {
                        for (Job<?, ?> job : owner.getAllJobs()) {
                            if (pullRequestJobNamePattern.matcher(job.getName()).matches()) {
                                if (!(job.getParent() instanceof MultiBranchProject)) {
                                    continue;
                                }
                                boolean propFound = false;
                                for (BranchProperty prop : ((MultiBranchProject) job.getParent()).getProjectFactory().
                                        getBranch(job).getProperties()) {
                                    if (!(prop instanceof TriggerPRUpdateBranchProperty)) {
                                        continue;
                                    }
                                    propFound = true;
                                    ParameterizedJobMixIn.scheduleBuild2(job, 0,
                                            new CauseAction(new GitHubPullRequestUpdateCause(pullRequestUrl)));
                                    break;
                                }

                                if (!propFound) {
                                    LOGGER.log(Level.FINE,
                                            "Job {0} for {1}:{2}/{3} does not have a trigger PR update branch property",
                                            new Object[] {
                                                    job.getFullName(),
                                                    changedRepository.getHost(),
                                                    changedRepository.getUserName(),
                                                    changedRepository.getRepositoryName()
                                            }
                                    );
                                }

                                jobFound = true;
                            }
                        }
                    }
                }
            }
            if (!jobFound) {
                LOGGER.log(Level.FINE, "PR update on {0}:{1}/{2} did not match any job",
                        new Object[] {
                                changedRepository.getHost(), changedRepository.getUserName(),
                                changedRepository.getRepositoryName()
                        }
                );
            }
        }
    });
}
 
Example #26
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void getMultiBranchPipelineActivityRuns() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    scheduleAndFindBranchProject(mp);
    j.waitUntilNoActivity();

    WorkflowJob p = findBranchProject(mp, "master");

    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(3, mp.getItems().size());

    //execute feature/ux-1 branch build
    p = findBranchProject(mp, "feature%2Fux-1");
    WorkflowRun b2 = p.getLastBuild();
    assertEquals(1, b2.getNumber());


    //execute feature 2 branch build
    p = findBranchProject(mp, "feature2");
    WorkflowRun b3 = p.getLastBuild();
    assertEquals(1, b3.getNumber());


    List<Map> resp = get("/organizations/jenkins/pipelines/p/runs", List.class);
    Assert.assertEquals(3, resp.size());
    Date d1 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String)resp.get(0).get("startTime"));
    Date d2 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String)resp.get(1).get("startTime"));
    Date d3 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String)resp.get(2).get("startTime"));

    Assert.assertTrue(d1.compareTo(d2) >= 0);
    Assert.assertTrue(d2.compareTo(d3) >= 0);

    for(Map m: resp){
        BuildData d;
        WorkflowRun r;
        if(m.get("pipeline").equals("master")){
            r = b1;
            d = b1.getAction(BuildData.class);
        } else if(m.get("pipeline").equals("feature2")){
            r = b3;
            d = b3.getAction(BuildData.class);
        } else{
            r = b2;
            d = b2.getAction(BuildData.class);
        }
        validateRun(r,m);
        String commitId = "";
        if(d != null) {
            commitId = d.getLastBuiltRevision().getSha1String();
            Assert.assertEquals(commitId, m.get("commitId"));
        }
    }
}
 
Example #27
Source File: RunImplTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test @Ignore
public void replayRunTestMB() throws Exception {
    j.createOnlineSlave(Label.get("remote"));

    sampleRepo.write("Jenkinsfile", "node('remote') {\n" +
        "    ws {\n" +
        "       checkout scm\n" +
        "       stage 'build'\n "+"node {echo 'Building'}\n"+
        "       stage 'test'\nnode { echo 'Testing'}\n"+
        "       stage 'deploy'\nnode { echo 'Deploying'}\n" +
        "       }\n" +
        "   }");
    sampleRepo.git("add", "Jenkinsfile");
    sampleRepo.git("commit", "--message=init");

    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }


    mp.scheduleBuild2(0).getFuture().get();
    WorkflowJob job1 = mp.getItem("master");
    WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
    j.waitForCompletion(b1);
    j.assertBuildStatusSuccess(b1);

    sampleRepo.write("file1", "");
    sampleRepo.git("add", "file1");
    sampleRepo.git("commit", "--message=init");

    WorkflowRun b2 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b2);

    Assert.assertNotEquals(new PipelineRunImpl(b1, null, null).getCommitId(), new PipelineRunImpl(b2, null, null).getCommitId());

    Map replayBuild = request().post("/organizations/jenkins/pipelines/p/branches/master/runs/"+ b1.getNumber()+"/replay").build(Map.class);
    Queue.Item item = j.getInstance().getQueue().getItem(Long.parseLong((String)replayBuild.get("id")));

    WorkflowRun replayedRun = (WorkflowRun)item.getFuture().get();

    Map r = request().get("/organizations/jenkins/pipelines/p/branches/master/runs/"+replayedRun.getNumber()+"/").build(Map.class);
    assertEquals(new PipelineRunImpl(b1,null, null).getCommitId(), r.get("commitId"));
}
 
Example #28
Source File: PRReviewGHEventSubscriber.java    From github-pr-comment-build-plugin with MIT License 4 votes vote down vote up
/**
 * Handles updates of pull requests.
 * @param event only PULL_REQUEST_REVIEW events
 * @param payload payload of gh-event. Never blank
 */
@Override
protected void onEvent(GHEvent event, String payload) {
    JSONObject json = JSONObject.fromObject(payload);

    JSONObject pullRequest = json.getJSONObject("pull_request");
    final String pullRequestUrl = pullRequest.getString("html_url");
    Integer pullRequestId = pullRequest.getInt("number");

    // Set some values used below
    final Pattern pullRequestJobNamePattern = Pattern.compile("^PR-" + pullRequestId + "\\b.*$",
            Pattern.CASE_INSENSITIVE);

    // Make sure the repository URL is valid
    String repoUrl = json.getJSONObject("repository").getString("html_url");
    Matcher matcher = REPOSITORY_NAME_PATTERN.matcher(repoUrl);
    if (!matcher.matches()) {
        LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl);
        return;
    }
    final GitHubRepositoryName changedRepository = GitHubRepositoryName.create(repoUrl);
    if (changedRepository == null) {
        LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl);
        return;
    }

    LOGGER.log(Level.FINE, "Received review on PR {1} for {2}", new Object[] { pullRequestId, repoUrl });
    ACL.impersonate(ACL.SYSTEM, new Runnable() {
        @Override
        public void run() {
            boolean jobFound = false;
            for (final SCMSourceOwner owner : SCMSourceOwners.all()) {
                for (SCMSource source : owner.getSCMSources()) {
                    if (!(source instanceof GitHubSCMSource)) {
                        continue;
                    }
                    GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
                    if (gitHubSCMSource.getRepoOwner().equalsIgnoreCase(changedRepository.getUserName()) &&
                            gitHubSCMSource.getRepository().equalsIgnoreCase(changedRepository.getRepositoryName())) {
                        for (Job<?, ?> job : owner.getAllJobs()) {
                            if (pullRequestJobNamePattern.matcher(job.getName()).matches()) {
                                if (!(job.getParent() instanceof MultiBranchProject)) {
                                    continue;
                                }
                                boolean propFound = false;
                                for (BranchProperty prop : ((MultiBranchProject) job.getParent()).getProjectFactory().
                                        getBranch(job).getProperties()) {
                                    if (!(prop instanceof TriggerPRReviewBranchProperty)) {
                                        continue;
                                    }
                                    propFound = true;
                                    ParameterizedJobMixIn.scheduleBuild2(job, 0,
                                            new CauseAction(new GitHubPullRequestReviewCause(pullRequestUrl)));
                                    break;
                                }

                                if (!propFound) {
                                    LOGGER.log(Level.FINE,
                                            "Job {0} for {1}:{2}/{3} does not have a trigger PR review branch property",
                                            new Object[] {
                                                    job.getFullName(),
                                                    changedRepository.getHost(),
                                                    changedRepository.getUserName(),
                                                    changedRepository.getRepositoryName()
                                            }
                                    );
                                }

                                jobFound = true;
                            }
                        }
                    }
                }
            }
            if (!jobFound) {
                LOGGER.log(Level.FINE, "PR review on {0}:{1}/{2} did not match any job",
                        new Object[] {
                                changedRepository.getHost(), changedRepository.getUserName(),
                                changedRepository.getRepositoryName()
                        }
                );
            }
        }
    });
}