Search in sources :

Example 1 with ArtifactArchiver

use of hudson.tasks.ArtifactArchiver 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 ArtifactArchiver

use of hudson.tasks.ArtifactArchiver in project artifact-manager-s3-plugin by jenkinsci.

the class JCloudsArtifactManagerTest method artifactBrowsingPerformance.

@Test
public void artifactBrowsingPerformance() throws Exception {
    ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(getArtifactManagerFactory());
    FreeStyleProject p = j.createFreeStyleProject();
    p.getBuildersList().add(new TestBuilder() {

        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            FilePath ws = build.getWorkspace();
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    ws.child(i + "/" + j + "/f").write(i + "-" + j, null);
                }
            }
            return true;
        }
    });
    p.getPublishersList().add(new ArtifactArchiver("**"));
    FreeStyleBuild b = j.buildAndAssertSuccess(p);
    httpLogging.record(InvokeHttpMethod.class, Level.FINE);
    httpLogging.capture(1000);
    JenkinsRule.WebClient wc = j.createWebClient();
    // Exercise DirectoryBrowserSupport & Run.getArtifactsUpTo
    System.err.println("build root");
    wc.getPage(b);
    System.err.println("artifact root");
    wc.getPage(b, "artifact/");
    System.err.println("3 subdir");
    wc.getPage(b, "artifact/3/");
    System.err.println("3/4 subdir");
    wc.getPage(b, "artifact/3/4/");
    int httpCount = httpLogging.getRecords().size();
    System.err.println("total count: " + httpCount);
    assertThat(httpCount, lessThanOrEqualTo(11));
}
Also used : FilePath(hudson.FilePath) ArtifactArchiver(hudson.tasks.ArtifactArchiver) IOException(java.io.IOException) FreeStyleBuild(hudson.model.FreeStyleBuild) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) TestBuilder(org.jvnet.hudson.test.TestBuilder) BuildListener(hudson.model.BuildListener) Launcher(hudson.Launcher) ArtifactManagerTest(org.jenkinsci.plugins.workflow.ArtifactManagerTest) Test(org.junit.Test)

Example 3 with ArtifactArchiver

use of hudson.tasks.ArtifactArchiver in project artifact-manager-s3-plugin by jenkinsci.

the class JCloudsArtifactManagerTest method archiveSingleLargeFile.

// @Test
public void archiveSingleLargeFile() throws Exception {
    ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(getArtifactManagerFactory());
    FreeStyleProject p = j.createFreeStyleProject();
    p.getBuildersList().add(new TestBuilder() {

        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            FilePath target = build.getWorkspace().child("out");
            long length = 2L * 1024 * 1024 * 1024;
            final FilePath src = new FilePath(Which.jarFile(Jenkins.class));
            final OutputStream out = target.write();
            try {
                do {
                    IOUtils.copy(src.read(), out);
                } while (target.length() < length);
            } finally {
                out.close();
            }
            return true;
        }
    });
    p.getPublishersList().add(new ArtifactArchiver("**/*"));
    FreeStyleBuild build = j.buildAndAssertSuccess(p);
    InputStream out = build.getArtifactManager().root().child("out").open();
    try {
        IOUtils.copy(out, new NullOutputStream());
    } finally {
        out.close();
    }
}
Also used : FilePath(hudson.FilePath) ArtifactArchiver(hudson.tasks.ArtifactArchiver) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) NullOutputStream(org.apache.commons.io.output.NullOutputStream) IOException(java.io.IOException) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) TestBuilder(org.jvnet.hudson.test.TestBuilder) BuildListener(hudson.model.BuildListener) Launcher(hudson.Launcher) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

Example 4 with ArtifactArchiver

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

the class PromotionProcessTest method test1.

@Test
public void test1() throws Exception {
    FreeStyleProject up = j.createFreeStyleProject("up");
    FreeStyleProject down = j.createFreeStyleProject();
    Recorder r1 = new ArtifactArchiver("a.jar", null, false);
    Recorder r2 = new Fingerprinter("", true);
    List<Recorder> recorders = Arrays.asList(r1, r2);
    // upstream job
    up.getBuildersList().add(Functions.isWindows() ? new BatchFile("date /t > a.jar") : 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 = j.createWebClient().getContextPath() + "job/up/lastSuccessfulBuild";
    String artifactUrl = baseUrl + "/artifact/a.jar";
    down.getBuildersList().add(Functions.isWindows() ? new BatchFile("powershell -command \"Invoke-WebRequest " + artifactUrl + " -OutFile a.jar\"\r\n" + "set /a \"exitCode=BUILD_NUMBER%%2\"\r\n" + "exit /b %exitCode%\r\n") : new Shell("wget -N " + artifactUrl + " \\\n" + "  || curl " + artifactUrl + " > 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 = j.assertBuildStatusSuccess(up.scheduleBuild2(0).get());
    j.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
    j.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.getTargetBuildOrFail(), up1);
        PromotedBuildAction badge = (PromotedBuildAction) up1.getBadgeActions().get(0);
        assertTrue(badge.contains(proc));
    }
    // make sure the UI persists the setup
    j.configRoundtrip(up);
}
Also used : BatchFile(hudson.tasks.BatchFile) 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) Test(org.junit.Test)

Example 5 with ArtifactArchiver

use of hudson.tasks.ArtifactArchiver in project hudson-2.x by hudson.

the class FailureBuildMail method artifactMatches.

/**
 * Check whether a path (/-separated) will be archived.
 */
public boolean artifactMatches(String path, AbstractBuild<?, ?> build) {
    ArtifactArchiver aa = build.getProject().getPublishersList().get(ArtifactArchiver.class);
    if (aa == null) {
        // LOGGER.finer("No ArtifactArchiver found");
        return false;
    }
    String artifacts = aa.getArtifacts();
    for (String include : artifacts.split("[, ]+")) {
        String pattern = include.replace(File.separatorChar, '/');
        if (pattern.endsWith("/")) {
            pattern += "**";
        }
        if (SelectorUtils.matchPath(pattern, path)) {
            // new Object[]{path, pattern});
            return true;
        }
    }
    // new Object[]{path, artifacts});
    return false;
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver)

Aggregations

ArtifactArchiver (hudson.tasks.ArtifactArchiver)12 FreeStyleProject (hudson.model.FreeStyleProject)9 Test (org.junit.Test)9 Run (hudson.model.Run)5 Shell (hudson.tasks.Shell)5 FreeStyleBuild (hudson.model.FreeStyleBuild)4 FilePath (hudson.FilePath)3 Launcher (hudson.Launcher)3 BuildListener (hudson.model.BuildListener)3 IOException (java.io.IOException)3 List (java.util.List)3 Map (java.util.Map)3 TestBuilder (org.jvnet.hudson.test.TestBuilder)3 Fingerprinter (hudson.tasks.Fingerprinter)2 Recorder (hudson.tasks.Recorder)2 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)2 DownstreamPassCondition (hudson.plugins.promoted_builds.conditions.DownstreamPassCondition)1 GlobalMatrixAuthorizationStrategy (hudson.security.GlobalMatrixAuthorizationStrategy)1 HudsonPrivateSecurityRealm (hudson.security.HudsonPrivateSecurityRealm)1 BatchFile (hudson.tasks.BatchFile)1