Search in sources :

Example 31 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method createUserFavouriteMultibranchTopLevelTest.

@Test
public void createUserFavouriteMultibranchTopLevelTest() 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");
    Map m = new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/p/favorite").jwtToken(token).data(ImmutableMap.of("favorite", true)).build(Map.class);
    Map branch = (Map) m.get("item");
    validatePipeline(p, branch);
    String c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);
    List l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    Assert.assertEquals(1, l.size());
    branch = (Map) ((Map) l.get(0)).get("item");
    validatePipeline(p, branch);
    c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/master/favorite/", getHrefFromLinks((Map) l.get(0), "self"));
    String ref = getHrefFromLinks((Map) l.get(0), "self");
    m = new RequestBuilder(baseUrl).put(getUrlFromHref(ref)).jwtToken(token).data(ImmutableMap.of("favorite", false)).build(Map.class);
    branch = (Map) m.get("item");
    validatePipeline(p, branch);
    c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);
    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);
}
Also used : GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) User(hudson.model.User) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 32 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method createUserFavouriteMultibranchBranchTest.

@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);
}
Also used : GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) User(hudson.model.User) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 33 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method favoritedFromClassicTest.

@Test
public void favoritedFromClassicTest() 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();
    Favorites.toggleFavorite(user, p);
    user.save();
    String token = getJwtToken(j.jenkins, "alice", "alice");
    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");
    validatePipeline(p, branch);
    String c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);
    String href = getHrefFromLinks((Map) l.get(0), "self");
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/master/favorite/", href);
    Map m = new RequestBuilder(baseUrl).put(getUrlFromHref(getUrlFromHref(href))).jwtToken(token).data(ImmutableMap.of("favorite", false)).build(Map.class);
    branch = (Map) m.get("item");
    validatePipeline(p, branch);
    c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);
    l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    Assert.assertEquals(0, l.size());
}
Also used : GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) User(hudson.model.User) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 34 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method getPipelineRunStopTest.

@Test
public void getPipelineRunStopTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build'); " + "   semaphore 's' " + "   stage ('Test'); " + "   echo ('Testing'); " + "}", false));
    WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
    SemaphoreStep.waitForStart("s/1", b1);
    Map r = null;
    for (int i = 0; i < 10; i++) {
        r = request().put("/organizations/jenkins/pipelines/pipeline1/runs/1/stop").build(Map.class);
        if (((String) r.get("state")).equals("FINISHED"))
            break;
        Thread.sleep(1000);
    }
    Assert.assertEquals(r.get("state"), "FINISHED");
    Assert.assertEquals(r.get("result"), "ABORTED");
    j.assertBuildStatus(Result.ABORTED, b1);
    FreeStyleProject p = j.createFreeStyleProject("pipeline5");
    p.getBuildersList().add(new Shell("echo hello!\nsleep 69"));
    FreeStyleBuild b2 = p.scheduleBuild2(0).waitForStart();
    for (int i = 0; i < 10; i++) {
        r = put("/organizations/jenkins/pipelines/pipeline5/runs/1/stop", null);
        if (((String) r.get("state")).equals("FINISHED"))
            break;
        Thread.sleep(1000);
    }
    Assert.assertEquals(r.get("state"), "FINISHED");
    Assert.assertEquals(r.get("result"), "ABORTED");
    j.assertBuildStatus(Result.ABORTED, b2);
}
Also used : Shell(hudson.tasks.Shell) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FreeStyleBuild(hudson.model.FreeStyleBuild) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 35 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method getPipelineRunblockingStopTest.

// TODO: Fix test - see JENKINS-38319
@Test
@Ignore
public void getPipelineRunblockingStopTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   sh('sleep 60') " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
    Map r = // default timeOutInSecs=10 sec
    request().put("/organizations/jenkins/pipelines/pipeline1/runs/1/stop/?blocking=true").build(Map.class);
    Assert.assertEquals(r.get("state"), "FINISHED");
    Assert.assertEquals(r.get("result"), "ABORTED");
    j.assertBuildStatus(Result.ABORTED, b1);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)100 Test (org.junit.Test)91 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)74 Map (java.util.Map)73 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)62 ImmutableMap (com.google.common.collect.ImmutableMap)55 List (java.util.List)34 ImmutableList (com.google.common.collect.ImmutableList)28 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)26 BranchSource (jenkins.branch.BranchSource)24 GitSCMSource (jenkins.plugins.git.GitSCMSource)24 SCMSource (jenkins.scm.api.SCMSource)23 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)20 RunList (hudson.util.RunList)19 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)17 ArrayList (java.util.ArrayList)10 URL (java.net.URL)9 Run (hudson.model.Run)8 Issue (org.jvnet.hudson.test.Issue)8 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)7