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());
}
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));
}
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();
}
}
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);
}
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());
}
Aggregations