Search in sources :

Example 1 with Shell

use of hudson.tasks.Shell in project blueocean-plugin by jenkinsci.

the class AbstractRunImplTest method testArtifactZipFileLink.

@Test
public void testArtifactZipFileLink() throws Exception {
    String JOB_NAME = "artifactTest";
    FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
    p.getBuildersList().add(new Shell("touch {{a..z},{A..Z},{0..99}}.txt"));
    p.getPublishersList().add(new ArtifactArchiver("*"));
    Run r = p.scheduleBuild2(0).waitForStart();
    r = j.waitForCompletion(r);
    Map m = request().get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/").build(Map.class);
    Assert.assertEquals(m.get("artifactsZipFile"), "/job/artifactTest/1/artifact/*zip*/archive.zip");
}
Also used : Shell(hudson.tasks.Shell) ArtifactArchiver(hudson.tasks.ArtifactArchiver) Run(hudson.model.Run) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) Test(org.junit.Test)

Example 2 with Shell

use of hudson.tasks.Shell 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 ('Build1'); " + "   sh('sleep 60') " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
    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")).equalsIgnoreCase("FINISHED"))
            continue;
        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")).equalsIgnoreCase("finished"))
            continue;
        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 3 with Shell

use of hudson.tasks.Shell in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method getPipelineRunsStopTest.

@Test
public void getPipelineRunsStopTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("p1");
    p.getBuildersList().add(new Shell("sleep 60"));
    FreeStyleBuild b = p.scheduleBuild2(0).waitForStart();
    //wait till its running
    do {
        //sleep for 10ms
        Thread.sleep(10);
    } while (b.hasntStartedYet());
    Map resp = put("/organizations/jenkins/pipelines/p1/runs/" + b.getId() + "/stop/?blocking=true&timeOutInSecs=2", Map.class);
    assertEquals("ABORTED", resp.get("result"));
}
Also used : Shell(hudson.tasks.Shell) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 4 with Shell

use of hudson.tasks.Shell in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method parameterizedFreestyleTest.

@Test
public void parameterizedFreestyleTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pp");
    p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("version", "1.0", "version number")));
    p.getBuildersList().add(new Shell("echo hello!"));
    Map resp = get("/organizations/jenkins/pipelines/pp/");
    List<Map<String, Object>> parameters = (List<Map<String, Object>>) resp.get("parameters");
    assertEquals(1, parameters.size());
    assertEquals("version", parameters.get(0).get("name"));
    assertEquals("StringParameterDefinition", parameters.get(0).get("type"));
    assertEquals("version number", parameters.get(0).get("description"));
    assertEquals("1.0", ((Map) parameters.get(0).get("defaultParameterValue")).get("value"));
    validatePipeline(p, resp);
    resp = post("/organizations/jenkins/pipelines/pp/runs/", ImmutableMap.of("parameters", ImmutableList.of(ImmutableMap.of("name", "version", "value", "2.0"))), 200);
    assertEquals("pp", resp.get("pipeline"));
    Thread.sleep(1000);
    resp = get("/organizations/jenkins/pipelines/pp/runs/1/");
    assertEquals("SUCCESS", resp.get("result"));
    assertEquals("FINISHED", resp.get("state"));
}
Also used : Shell(hudson.tasks.Shell) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 5 with Shell

use of hudson.tasks.Shell in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method getPipelineRunsTest.

@Test
public void getPipelineRunsTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pipeline6");
    p.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    FreeStyleBuild b = p.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b);
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline6/runs", List.class);
    assertEquals(1, resp.size());
    Map lr = resp.get(0);
    validateRun(b, lr);
}
Also used : Shell(hudson.tasks.Shell) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

Shell (hudson.tasks.Shell)25 Test (org.junit.Test)21 FreeStyleProject (hudson.model.FreeStyleProject)19 Map (java.util.Map)15 FreeStyleBuild (hudson.model.FreeStyleBuild)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 Run (hudson.model.Run)4 ArtifactArchiver (hudson.tasks.ArtifactArchiver)4 List (java.util.List)3 ImmutableList (com.google.common.collect.ImmutableList)2 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)2 Project (hudson.model.Project)2 StringParameterDefinition (hudson.model.StringParameterDefinition)2 DownstreamPassCondition (hudson.plugins.promoted_builds.conditions.DownstreamPassCondition)2 Stack (java.util.Stack)2 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)2 CauseAction (hudson.model.CauseAction)1 ParametersAction (hudson.model.ParametersAction)1 Queue (hudson.model.Queue)1 StringParameterValue (hudson.model.StringParameterValue)1