Search in sources :

Example 6 with ArtifactArchiver

use of hudson.tasks.ArtifactArchiver in project workflow-cps-plugin by jenkinsci.

the class ArgumentsActionImplTest method testReallyUnusualStepInstantiations.

@Test
public void testReallyUnusualStepInstantiations() throws Exception {
    WorkflowJob job = r.jenkins.createProject(WorkflowJob.class, "unusualInstantiation");
    job.setDefinition(new CpsFlowDefinition(" node() {\n" + "   writeFile text: 'hello world', file: 'msg.out'\n" + // note, not whitelisted
    "   step(new hudson.tasks.ArtifactArchiver('msg.out'))\n" + "}", false));
    WorkflowRun run = r.buildAndAssertSuccess(job);
    LinearScanner scan = new LinearScanner();
    FlowNode testNode = scan.findFirstMatch(run.getExecution().getCurrentHeads().get(0), new NodeStepTypePredicate("step"));
    ArgumentsAction act = testNode.getPersistentAction(ArgumentsAction.class);
    Assert.assertNotNull(act);
    Object delegate = act.getArgumentValue("delegate");
    Assert.assertThat(delegate, instanceOf(ArtifactArchiver.class));
    Assert.assertEquals("msg.out", ((ArtifactArchiver) delegate).getArtifacts());
    Assert.assertFalse(((ArtifactArchiver) delegate).isFingerprint());
}
Also used : ArgumentsAction(org.jenkinsci.plugins.workflow.actions.ArgumentsAction) NodeStepTypePredicate(org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate) ArtifactArchiver(hudson.tasks.ArtifactArchiver) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) LinearScanner(org.jenkinsci.plugins.workflow.graphanalysis.LinearScanner) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 7 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 8 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 9 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 10 with ArtifactArchiver

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

the class ArtifactsSecurity564 method testArtifactsWithPermissions.

/**
 * Uses matrix-auth to provide artifacts permission.
 *
 * If hudson.security.ArtifactsPermission is set then the user must have Run.ARTIFACTS set.
 *
 * @throws Exception
 */
@Issue("SECURITY-564")
@Test
public void testArtifactsWithPermissions() throws Exception {
    String JOB_NAME = "artifactPermissions";
    String artfictPath = "a/b/c";
    HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false);
    realm.createAccount("alice", "alice");
    realm.createAccount("bob", "bob");
    j.jenkins.setSecurityRealm(realm);
    GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy();
    j.jenkins.setAuthorizationStrategy(as);
    as.add(Hudson.READ, "alice");
    as.add(Item.READ, "alice");
    as.add(Run.ARTIFACTS, "alice");
    as.add(Hudson.READ, "bob");
    as.add(Item.READ, "bob");
    FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
    p.getBuildersList().add(new ArtifactBuilder(artfictPath, 100));
    p.getPublishersList().add(new ArtifactArchiver("**/*"));
    Run r = p.scheduleBuild2(0).waitForStart();
    r = j.waitForCompletion(r);
    List artifacts = request().authAlice().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(artfictPath + "/0.txt", ((Map) artifacts.get(0)).get("path"));
    Assert.assertEquals("/job/artifactPermissions/1/artifact/" + artfictPath + "/0.txt", ((Map) artifacts.get(0)).get("url"));
    List artifactsBob = request().auth("bob", "bob").get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/artifacts").build(List.class);
    Assert.assertEquals(0, artifactsBob.size());
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) Run(hudson.model.Run) List(java.util.List) FreeStyleProject(hudson.model.FreeStyleProject) HudsonPrivateSecurityRealm(hudson.security.HudsonPrivateSecurityRealm) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

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