Search in sources :

Example 1 with BlueArtifact

use of io.jenkins.blueocean.rest.model.BlueArtifact in project blueocean-plugin by jenkinsci.

the class HTMLArtifactTest method resolveArtifact.

@Test
public void resolveArtifact() throws Exception {
    WorkflowJob p = j.createProject(WorkflowJob.class, "project");
    URL resource = Resources.getResource(getClass(), "HTMLArtifactTest.jenkinsfile");
    String jenkinsFile = Resources.toString(resource, Charsets.UTF_8);
    p.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
    p.save();
    Run r = p.scheduleBuild2(0).waitForStart();
    j.waitForCompletion(r);
    BluePipeline bluePipeline = (BluePipeline) BluePipelineFactory.resolve(p);
    BlueArtifactContainer artifacts = bluePipeline.getLatestRun().getArtifacts();
    Assert.assertEquals(1, Iterators.size(artifacts.iterator()));
    BlueArtifact artifact = Iterators.getOnlyElement(artifacts.iterator());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/project/runs/1/artifacts/io.jenkins.blueocean.htmlpublisher.HTMLArtifact%253AMy%252520Cool%252520report/", artifact.getLink().getHref());
    Assert.assertEquals("My Cool report", artifact.getName());
    Assert.assertEquals("My Cool report", artifact.getPath());
    Assert.assertEquals("/job/project/1/My_Cool_report", artifact.getUrl());
    Assert.assertEquals(-1, artifact.getSize());
    Assert.assertFalse(artifact.isDownloadable());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BlueArtifact(io.jenkins.blueocean.rest.model.BlueArtifact) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) BlueArtifactContainer(io.jenkins.blueocean.rest.model.BlueArtifactContainer) Run(hudson.model.Run) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) URL(java.net.URL) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 2 with BlueArtifact

use of io.jenkins.blueocean.rest.model.BlueArtifact in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method testArtifactsRunApi.

@Test
public void testArtifactsRunApi() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pipeline1");
    p.getBuildersList().add(new TestBuilder() {

        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            FilePath ws = build.getWorkspace();
            if (ws == null) {
                return false;
            }
            FilePath dir = ws.child("dir");
            dir.mkdirs();
            dir.child("fizz").write("contents", null);
            dir.child("lodge").symlinkTo("fizz", listener);
            return true;
        }
    });
    ArtifactArchiver aa = new ArtifactArchiver("dir/fizz");
    aa.setAllowEmptyArchive(true);
    p.getPublishersList().add(aa);
    FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
    List artifacts = get("/organizations/jenkins/pipelines/pipeline1/runs/" + b.getId() + "/artifacts", List.class);
    assertEquals(1, artifacts.size());
    assertEquals("fizz", ((Map) artifacts.get(0)).get("name"));
    String artifactName = (String) ((Map) artifacts.get(0)).get("name");
    String name = ArtifactImpl.class.getName() + ":" + artifactName;
    ArtifactContainerImpl container = new ArtifactContainerImpl(b, new Reachable() {

        @Override
        public Link getLink() {
            return new Link("/blue/rest/organizations/jenkins/pipelines/pipeline1/runs/1/artifacts/");
        }
    });
    BlueArtifact blueArtifact = container.get(name);
    assertNotNull(blueArtifact);
}
Also used : FilePath(hudson.FilePath) ArtifactArchiver(hudson.tasks.ArtifactArchiver) IOException(java.io.IOException) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) TestBuilder(org.jvnet.hudson.test.TestBuilder) BuildListener(hudson.model.BuildListener) Reachable(io.jenkins.blueocean.rest.Reachable) BlueArtifact(io.jenkins.blueocean.rest.model.BlueArtifact) Launcher(hudson.Launcher) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ArtifactContainerImpl(io.jenkins.blueocean.service.embedded.rest.ArtifactContainerImpl) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Aggregations

BlueArtifact (io.jenkins.blueocean.rest.model.BlueArtifact)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 FilePath (hudson.FilePath)1 Launcher (hudson.Launcher)1 BuildListener (hudson.model.BuildListener)1 FreeStyleBuild (hudson.model.FreeStyleBuild)1 FreeStyleProject (hudson.model.FreeStyleProject)1 Run (hudson.model.Run)1 ArtifactArchiver (hudson.tasks.ArtifactArchiver)1 Reachable (io.jenkins.blueocean.rest.Reachable)1 Link (io.jenkins.blueocean.rest.hal.Link)1 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)1 BlueArtifactContainer (io.jenkins.blueocean.rest.model.BlueArtifactContainer)1 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)1 ArtifactContainerImpl (io.jenkins.blueocean.service.embedded.rest.ArtifactContainerImpl)1 IOException (java.io.IOException)1 URL (java.net.URL)1 List (java.util.List)1 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)1