Search in sources :

Example 1 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class GitReadSaveService method makeSaveRequest.

static GitReadSaveRequest makeSaveRequest(Item item, String branch, String commitMessage, String sourceBranch, String filePath, byte[] contents) {
    String defaultBranch = "master";
    GitSCMSource gitSource = null;
    if (item instanceof MultiBranchProject<?, ?>) {
        MultiBranchProject<?, ?> mbp = (MultiBranchProject<?, ?>) item;
        for (SCMSource s : mbp.getSCMSources()) {
            if (s instanceof GitSCMSource) {
                gitSource = (GitSCMSource) s;
            }
        }
    }
    return new GitBareRepoReadSaveRequest(gitSource, StringUtils.defaultIfEmpty(branch, defaultBranch), commitMessage, StringUtils.defaultIfEmpty(sourceBranch, defaultBranch), filePath, contents);
}
Also used : MultiBranchProject(jenkins.branch.MultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource)

Example 2 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class SseEventTest method multiBranchJobEventsWithCustomOrg.

@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]);
    }
}
Also used : Message(org.jenkinsci.plugins.pubsub.Message) ChannelSubscriber(org.jenkinsci.plugins.pubsub.ChannelSubscriber) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) MockFolder(org.jvnet.hudson.test.MockFolder) BranchSource(jenkins.branch.BranchSource) SSEConnection(io.jenkins.blueocean.events.sse.SSEConnection) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) OneShotEvent(hudson.util.OneShotEvent) Test(org.junit.Test)

Example 3 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method encodedStepDescription.

@Test
public void encodedStepDescription() throws Exception {
    setupScm("pipeline {\n" + "  agent any\n" + "  stages {\n" + "    stage('Build') {\n" + "      steps {\n" + "          sh 'echo \"\\033[32m some text \\033[0m\"'    \n" + "      }\n" + "    }\n" + "  }\n" + "}");
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false)));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    mp.scheduleBuild2(0).getFuture().get();
    j.waitUntilNoActivity();
    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    Assert.assertEquals(Result.SUCCESS, b1.getResult());
    List<FlowNode> stages = getStages(NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1));
    Assert.assertEquals(1, stages.size());
    Assert.assertEquals("Build", stages.get(0).getDisplayName());
    List<Map> resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/", List.class);
    Assert.assertEquals(1, resp.size());
    Assert.assertEquals("Build", resp.get(0).get("displayName"));
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/steps/", List.class);
    Assert.assertEquals(2, resp.size());
    assertNotNull(resp.get(0).get("displayName"));
    assertEquals("Shell Script", resp.get(1).get("displayName"));
    assertEquals("echo \"\u001B[32m some text \u001B[0m\"", resp.get(1).get("displayDescription"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) RunList(hudson.util.RunList) List(java.util.List) ExtensionList(hudson.ExtensionList) 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) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 4 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method testMultiBranchPipelineBranchUnsecurePermissions.

@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"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) MockFolder(org.jvnet.hudson.test.MockFolder) BranchSource(jenkins.branch.BranchSource) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) Test(org.junit.Test)

Example 5 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method parameterizedBranchTest.

@Test
public void parameterizedBranchTest() throws Exception {
    setupParameterizedScm();
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo2.toString(), "", "*", "", false)));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, branches[1]);
    j.waitUntilNoActivity();
    Map resp = get("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/", Map.class);
    List<Map<String, Object>> parameters = (List<Map<String, Object>>) resp.get("parameters");
    Assert.assertEquals(1, parameters.size());
    Assert.assertEquals("param1", parameters.get(0).get("name"));
    Assert.assertEquals("StringParameterDefinition", parameters.get(0).get("type"));
    Assert.assertEquals("string param", parameters.get(0).get("description"));
    Assert.assertEquals("xyz", ((Map) parameters.get(0).get("defaultParameterValue")).get("value"));
    resp = post("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/runs/", MapsHelper.of("parameters", Arrays.asList(MapsHelper.of("name", "param1", "value", "abc"))), 200);
    Assert.assertEquals(branches[1], resp.get("pipeline"));
    Thread.sleep(5000);
    resp = get("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/runs/2/");
    Assert.assertEquals("Response should be SUCCESS: " + resp.toString(), "SUCCESS", resp.get("result"));
    Assert.assertEquals("Response should be FINISHED: " + resp.toString(), "FINISHED", resp.get("state"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) 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) Map(java.util.Map) Test(org.junit.Test)

Aggregations

SCMSource (jenkins.scm.api.SCMSource)40 GitSCMSource (jenkins.plugins.git.GitSCMSource)36 BranchSource (jenkins.branch.BranchSource)35 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)35 Test (org.junit.Test)32 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)29 Map (java.util.Map)26 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)24 List (java.util.List)14 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)12 ArrayList (java.util.ArrayList)11 Queue (hudson.model.Queue)5 User (hudson.model.User)5 MockFolder (org.jvnet.hudson.test.MockFolder)5 ExtensionList (hudson.ExtensionList)3 FreeStyleProject (hudson.model.FreeStyleProject)3 RunList (hudson.util.RunList)3 MultiBranchProject (jenkins.branch.MultiBranchProject)3 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)3 Ignore (org.junit.Ignore)3