Search in sources :

Example 6 with Shell

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

the class PipelineApiTest method testNewPipelineQueueItem.

@Test
public void testNewPipelineQueueItem() throws Exception {
    FreeStyleProject p1 = j.createFreeStyleProject("pipeline1");
    FreeStyleProject p2 = j.createFreeStyleProject("pipeline2");
    FreeStyleProject p3 = j.createFreeStyleProject("pipeline3");
    p1.getBuildersList().add(new Shell("echo hello!\nsleep 300"));
    p2.getBuildersList().add(new Shell("echo hello!\nsleep 300"));
    p3.getBuildersList().add(new Shell("echo hello!\nsleep 300"));
    p1.scheduleBuild2(0).waitForStart();
    p2.scheduleBuild2(0).waitForStart();
    Map r = request().post("/organizations/jenkins/pipelines/pipeline3/runs/").build(Map.class);
    assertNotNull(p3.getQueueItem());
    String id = Long.toString(p3.getQueueItem().getId());
    assertEquals(id, r.get("id"));
    delete("/organizations/jenkins/pipelines/pipeline3/queue/" + id + "/");
    Queue.Item item = j.jenkins.getQueue().getItem(Long.parseLong(id));
    assertTrue(item instanceof Queue.LeftItem);
    assertTrue(((Queue.LeftItem) item).isCancelled());
}
Also used : Shell(hudson.tasks.Shell) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Queue(hudson.model.Queue) Test(org.junit.Test)

Example 7 with Shell

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

the class PipelineApiTest method getPipelineRunTest.

@Test
public void getPipelineRunTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pipeline4");
    p.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    FreeStyleBuild b = p.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b);
    Map resp = get("/organizations/jenkins/pipelines/pipeline4/runs/" + b.getId());
    validateRun(b, resp);
}
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 8 with Shell

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

the class ArtifactContainerImplTest method testArtifact.

//@Test TODO needs viveks input
public void testArtifact() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
    p.getBuildersList().add(new Shell("mkdir -p test/me/out; touch test/me/out/{{a..z},{A..Z},{0..99}}.txt"));
    p.getPublishersList().add(new ArtifactArchiver("**/*"));
    Run r = p.scheduleBuild2(0).waitForStart();
    r = j.waitForCompletion(r);
    Map artifact = request().get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/artifacts/test%252Fme%252Fout%252F0.txt").build(Map.class);
    Assert.assertEquals(100, artifact.size());
}
Also used : Shell(hudson.tasks.Shell) ArtifactArchiver(hudson.tasks.ArtifactArchiver) Run(hudson.model.Run) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map)

Example 9 with Shell

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

the class ArtifactContainerImplTest method testArtifactsListing.

@Test
public void testArtifactsListing() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
    p.getBuildersList().add(new Shell("#!/bin/bash\nmkdir -p test/me/out; cd test/me/out; touch {0..105}.txt"));
    p.getPublishersList().add(new ArtifactArchiver("**/*"));
    Run r = p.scheduleBuild2(0).waitForStart();
    r = j.waitForCompletion(r);
    List artifacts = request().get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/artifacts").build(List.class);
    Assert.assertEquals(100, artifacts.size());
    Assert.assertEquals(0, ((Map) artifacts.get(0)).get("size"));
    Assert.assertEquals("test/me/out/0.txt", ((Map) artifacts.get(0)).get("path"));
    Assert.assertEquals("/job/artifactTest/1/artifact/test/me/out/0.txt", ((Map) artifacts.get(0)).get("url"));
}
Also used : Shell(hudson.tasks.Shell) ArtifactArchiver(hudson.tasks.ArtifactArchiver) Run(hudson.model.Run) List(java.util.List) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 10 with Shell

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

the class PromotionProcessTest method test1.

public void test1() throws Exception {
    FreeStyleProject up = createFreeStyleProject("up");
    FreeStyleProject down = createFreeStyleProject();
    List<Recorder> recorders = Arrays.asList(new ArtifactArchiver("a.jar", null, false), new Fingerprinter("", true));
    // upstream job
    up.getBuildersList().add(new Shell("date > a.jar"));
    up.getPublishersList().replaceBy(recorders);
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(up);
    up.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    // this is the test job
    String baseUrl = new WebClient().getContextPath() + "job/up/lastSuccessfulBuild";
    down.getBuildersList().add(new Shell("wget -N " + baseUrl + "/artifact/a.jar \\\n" + "  || curl " + baseUrl + "/artifact/a.jar > a.jar\n" + // expr exits with non-zero status if result is zero
    "expr $BUILD_NUMBER % 2 - 1\n"));
    down.getPublishersList().replaceBy(recorders);
    // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
    fireItemListeners();
    // not yet promoted while the downstream is failing
    FreeStyleBuild up1 = assertBuildStatusSuccess(up.scheduleBuild2(0).get());
    assertBuildStatus(Result.FAILURE, down.scheduleBuild2(0).get());
    // give it a time to not promote
    Thread.sleep(1000);
    assertEquals(0, proc.getBuilds().size());
    // a successful downstream build promotes upstream
    assertBuildStatusSuccess(down.scheduleBuild2(0).get());
    // give it a time to promote
    Thread.sleep(1000);
    assertEquals(1, proc.getBuilds().size());
    {
        // verify that it promoted the right stuff
        Promotion pb = proc.getBuilds().get(0);
        assertSame(pb.getTarget(), up1);
        PromotedBuildAction badge = (PromotedBuildAction) up1.getBadgeActions().get(0);
        assertTrue(badge.contains(proc));
    }
    // make sure the UI persists the setup
    configRoundtrip(up);
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver) DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) Recorder(hudson.tasks.Recorder) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Shell(hudson.tasks.Shell) Fingerprinter(hudson.tasks.Fingerprinter)

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