hudson.tasks.ArtifactArchiver Java Examples

The following examples show how to use hudson.tasks.ArtifactArchiver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArtifactContainerImplTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@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"));
 }
 
Example #2
Source File: AquaMicroScannerBuilder.java    From aqua-microscanner-plugin with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") // No idea why this is needed
private void archiveArtifacts(Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener)
		throws java.lang.InterruptedException {
	ArtifactArchiver artifactArchiver = new ArtifactArchiver("scanout*");
	artifactArchiver.perform(build, workspace, launcher, listener);
	ArtifactArchiver styleArtifactArchiver = new ArtifactArchiver("styles.css");
	styleArtifactArchiver.perform(build, workspace, launcher, listener);
}
 
Example #3
Source File: BuildWorker.java    From anchore-container-scanner-plugin with Apache License 2.0 5 votes vote down vote up
public void setupBuildReports() throws AbortException {
  try {
    // store anchore output json files using jenkins archiver (for remote storage as well)
    console.logDebug("Archiving results");
    //      FilePath buildWorkspaceFP = build.getWorkspace();
    //      if (null != buildWorkspaceFP) {
    ArtifactArchiver artifactArchiver = new ArtifactArchiver(jenkinsOutputDirName + "/");
    artifactArchiver.perform(build, workspace, launcher, listener);
    //      } else {
    //        console.logError("Unable to archive results due to an invalid reference to Jenkins build workspace");
    //        throw new AbortException("Unable to archive results due to an invalid reference to Jenkins build workspace");
    //      }

    // add the link in jenkins UI for anchore results
    console.logDebug("Setting up build results");

    
    if (finalAction != null) {
      build.addAction(new AnchoreAction(build, finalAction.toString(), jenkinsOutputDirName, gateOutputFileName, queryOutputMap,
          gateSummary.toString(), cveListingFileName, totalStopActionCount, totalWarnActionCount, totalGoActionCount));
    } else {
      build.addAction(new AnchoreAction(build, "", jenkinsOutputDirName, gateOutputFileName, queryOutputMap, gateSummary.toString(),
          cveListingFileName, totalStopActionCount, totalWarnActionCount, totalGoActionCount));
    }
    //    } catch (AbortException e) { // probably caught one of the thrown exceptions, let it pass through
    //      throw e;
  } catch (Exception e) { // caught unknown exception, log it and wrap it
    console.logError("Failed to setup build results due to an unexpected error", e);
    throw new AbortException(
        "Failed to setup build results due to an unexpected error. Please refer to above logs for more information");
  }
}
 
Example #4
Source File: ArtifactsSecurity564.java    From blueocean-plugin with MIT License 5 votes vote down vote up
/**
 * 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 artifactPath = "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(artifactPath, 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(artifactPath + "/0.txt", ((Map) artifacts.get(0)).get("path"));
    Assert.assertEquals("/job/artifactPermissions/1/artifact/"+ artifactPath +"/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());
}
 
Example #5
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@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 artifactId = (String) ((Map) artifacts.get(0)).get("id");
    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(artifactId);
    assertNotNull(blueArtifact);
}
 
Example #6
Source File: ArtifactContainerImplTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test @Ignore
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());
}
 
Example #7
Source File: RunImplTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@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");
}