Search in sources :

Example 21 with BranchSource

use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.

the class RunImplTest method replayRunTestMB.

// Disabled, see JENKINS-40084
@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"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) Queue(hudson.model.Queue) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 22 with BranchSource

use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method resolveMbpLink.

@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());
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) FreeStyleProject(hudson.model.FreeStyleProject) BranchSource(jenkins.branch.BranchSource) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Test(org.junit.Test)

Example 23 with BranchSource

use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.

the class JobAnalyticsTest method createMultiBranch.

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());
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Example 24 with BranchSource

use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.

the class AbstractMultiBranchCreateRequest method create.

@Override
@SuppressWarnings("unchecked")
public BluePipeline create(@Nonnull BlueOrganization organization, @Nonnull Reachable parent) throws IOException {
    validateInternal(getName(), scmConfig, organization);
    MultiBranchProject project = createMultiBranchProject(organization);
    assignCredentialToProject(scmConfig, project);
    SCMSource source = createSource(project, scmConfig).withId("blueocean");
    project.setSourcesList(Collections.singletonList(new BranchSource(source)));
    source.afterSave();
    project.save();
    final boolean hasJenkinsfile = repoHasJenkinsFile(source);
    if (!hasJenkinsfile) {
        sendMultibranchIndexingCompleteEvent(project, 5);
        AbstractScmSourceEvent scmSourceEvent = getScmSourceEvent(project, source);
        if (scmSourceEvent != null) {
            SCMSourceEvent.fireNow(scmSourceEvent);
        }
    } else {
        project.scheduleBuild(new Cause.UserIdCause());
    }
    return BluePipelineFactory.getPipelineInstance(project, OrganizationFactory.getInstance().getContainingOrg(project.getItemGroup()));
}
Also used : Cause(hudson.model.Cause) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) MultiBranchProject(jenkins.branch.MultiBranchProject) SCMSource(jenkins.scm.api.SCMSource) BranchSource(jenkins.branch.BranchSource)

Example 25 with BranchSource

use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getPipelineJobActivitiesNoBranches.

@Test
public void getPipelineJobActivitiesNoBranches() 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/activities").build(List.class);
    Assert.assertEquals(0, l.size());
    List branches = request().get("/organizations/jenkins/pipelines/p/branches").build(List.class);
    Assert.assertEquals(0, branches.size());
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Test(org.junit.Test)

Aggregations

BranchSource (jenkins.branch.BranchSource)42 GitSCMSource (jenkins.plugins.git.GitSCMSource)39 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)39 SCMSource (jenkins.scm.api.SCMSource)35 Test (org.junit.Test)34 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)32 Map (java.util.Map)26 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)25 List (java.util.List)16 ArrayList (java.util.ArrayList)15 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)13 User (hudson.model.User)6 Queue (hudson.model.Queue)5 MockFolder (org.jvnet.hudson.test.MockFolder)5 ExtensionList (hudson.ExtensionList)3 FreeStyleProject (hudson.model.FreeStyleProject)3 RunList (hudson.util.RunList)3 ImmutableList (com.google.common.collect.ImmutableList)2 Cause (hudson.model.Cause)2 OneShotEvent (hudson.util.OneShotEvent)2