/** Test copying artifacts from all configurations of a matrix job */ @Test public void testMatrixAll() throws Exception { MatrixProject mp = createMatrixProject(); mp.setAxes(new AxisList(new Axis("ARCH", "sparc", "x86"))); mp.getBuildersList().add(new ArchMatrixBuilder()); mp.getPublishersList().add(new ArtifactArchiver("target/*", "", false, false)); rule.assertBuildStatusSuccess(mp.scheduleBuild2(0, new UserCause()).get()); FreeStyleProject p = createProject(mp.getName(), null, "", "", true, false, false, true); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); rule.assertBuildStatusSuccess(b); assertFile(true, "ARCH=sparc/target/readme.txt", b); assertFile(true, "ARCH=sparc/target/sparc.out", b); assertFile(true, "ARCH=x86/target/readme.txt", b); assertFile(true, "ARCH=x86/target/x86.out", b); }
/** Test copying from maven job where artifacts manually archived instead of automatic */ @Test public void testMavenJobWithArchivePostBuildStep() throws Exception { MavenModuleSet mp = setupMavenJob(); // Turn off automatic archiving and use a post-build step instead. // Artifacts will be stored with the parent build instead of the child module builds. mp.setIsArchivingDisabled(true); mp.getPublishersList().add(new ArtifactArchiver("moduleB/*.xml", "", false, false)); rule.assertBuildStatusSuccess(mp.scheduleBuild2(0, new UserCause()).get()); FreeStyleProject p = createProject(mp.getName(), null, "", "", true, false, false, true); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); // Archived artifact should be copied: assertFile(true, "moduleB/pom.xml", b); // None of the maven artifacts should be archived or copied: String dir = "org.jvnet.hudson.main.test.multimod/"; assertFile(false, dir + "moduleA/1.0-SNAPSHOT/moduleA-1.0-SNAPSHOT.jar", b); assertFile(false, dir + pomName("moduleA", "1.0-SNAPSHOT"), b); assertFile(false, dir + "moduleB/1.0-SNAPSHOT/moduleB-1.0-SNAPSHOT.jar", b); assertFile(false, dir + pomName("moduleB", "1.0-SNAPSHOT"), b); assertFile(false, dir + "moduleC/1.0-SNAPSHOT/moduleC-1.0-SNAPSHOT.jar", b); assertFile(false, dir + pomName("moduleC", "1.0-SNAPSHOT"), b); }
@Issue("JENKINS-19833") @Test public void testMostlyAbsolute() throws Exception { MockFolder folder = rule.jenkins.createProject(MockFolder.class, "folder"); FreeStyleProject other = folder.createProject(FreeStyleProject.class, "foo"); other.getBuildersList().add(new ArtifactBuilder()); other.getPublishersList().add(new ArtifactArchiver("**", "", false, false)); MockFolder folder2 = rule.jenkins.createProject(MockFolder.class, "other"); FreeStyleProject p = folder2.createProject(FreeStyleProject.class, "bar"); // "folder/foo" should be resolved as "/folder/foo" even from "/other/bar", for backward compatibility p.getBuildersList().add(CopyArtifactUtil.createRunSelector("folder/foo", null, new StatusRunSelector(StatusRunSelector.BuildStatus.STABLE), "", "", false, false, true)); rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get()); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); rule.assertBuildStatusSuccess(b); assertFile(true, "foo.txt", b); }
@Issue("JENKINS-20546") @Test public void testSymlinks() throws Exception { FreeStyleProject p1 = rule.createFreeStyleProject("p1"); p1.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("plain").write("text", null); build.getWorkspace().child("link1").symlinkTo("plain", listener); build.getWorkspace().child("link2").symlinkTo("nonexistent", listener); return true; } }); p1.getPublishersList().add(new ArtifactArchiver("**", "", false, false)); rule.buildAndAssertSuccess(p1); FreeStyleProject p2 = rule.createFreeStyleProject("p2"); p2.getBuildersList().add(CopyArtifactUtil.createRunSelector("p1", null, new StatusRunSelector(StatusRunSelector.BuildStatus.STABLE), null, "", false, false, true)); FreeStyleBuild b = rule.buildAndAssertSuccess(p2); FilePath ws = b.getWorkspace(); assertEquals("text", ws.child("plain").readToString()); assertEquals("plain", ws.child("link1").readLink()); assertEquals("nonexistent", ws.child("link2").readLink()); }
public boolean executeCheck(Item item) { LOG.log(Level.FINE, "executeCheck " + item); if (item instanceof Project) { Project project = (Project) item; DescribableList<Publisher, Descriptor<Publisher>> publishersList = project.getPublishersList(); for (Publisher publisher : publishersList) { if (publisher instanceof ArtifactArchiver) { LOG.log(Level.FINEST, "ArtifactChecker " + publisher); return (((ArtifactArchiver) publisher).getArtifacts() == null || (((ArtifactArchiver) publisher).getArtifacts() != null && ((ArtifactArchiver) publisher).getArtifacts().length() == 0)); } } } return false; }
private MatrixProject createMatrixArtifactProject() throws IOException { MatrixProject p = createMatrixProject(); p.setAxes(new AxisList(new Axis("FOO", "one", "two"))); p.getBuildersList().add(new ArtifactBuilder()); p.getPublishersList().add(new ArtifactArchiver("**", "", false, false)); return p; }
/** Test copy from workspace containing default ant excludes */ @Test public void testDefaultExcludes() throws Exception { FreeStyleProject other = rule.createFreeStyleProject(), p = rule.createFreeStyleProject(); p.getBuildersList().add(CopyArtifactUtil.createRunSelector(other.getName(), "", new StatusRunSelector(StatusRunSelector.BuildStatus.STABLE), "", "", false, false)); other.getBuildersList().add(new ArtifactBuilder()); ArtifactArchiver aa = new ArtifactArchiver("**/*"); aa.setDefaultExcludes(false); other.getPublishersList().add(aa); rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get()); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); rule.assertBuildStatusSuccess(b); assertFile(true, ".hg/defaultexclude.txt", b); }
@Test public void testExcludes() throws Exception { FreeStyleProject other = rule.createFreeStyleProject(), p = rule.createFreeStyleProject(); p.getBuildersList().add(CopyArtifactUtil.createRunSelector(other.getName(), "", new StatusRunSelector(StatusRunSelector.BuildStatus.STABLE), "**", ".hg/**", "", false, false, true)); other.getBuildersList().add(new ArtifactBuilder()); other.getPublishersList().add(new ArtifactArchiver("**/*")); rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get()); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); rule.assertBuildStatusSuccess(b); assertFile(true, "subdir/subfoo.txt", b); assertFile(false, ".hg/defaultexclude.txt", b); }
@Test public void testDefaultExcludesWithFlatten() throws Exception { FreeStyleProject other = rule.createFreeStyleProject(), p = rule.createFreeStyleProject(); p.getBuildersList().add(CopyArtifactUtil.createRunSelector(other.getName(), "", new StatusRunSelector(StatusRunSelector.BuildStatus.STABLE), "", "", true, false)); other.getBuildersList().add(new ArtifactBuilder()); ArtifactArchiver aa = new ArtifactArchiver("**/*"); aa.setDefaultExcludes(false); other.getPublishersList().add(aa); rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get()); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); rule.assertBuildStatusSuccess(b); assertFile(true, "defaultexclude.txt", b); }
@Test public void testExcludesWithFlatten() throws Exception { FreeStyleProject other = rule.createFreeStyleProject(), p = rule.createFreeStyleProject(); p.getBuildersList().add(CopyArtifactUtil.createRunSelector(other.getName(), "", new StatusRunSelector(StatusRunSelector.BuildStatus.STABLE), "**", ".hg/**", "", true, false, true)); other.getBuildersList().add(new ArtifactBuilder()); other.getPublishersList().add(new ArtifactArchiver("**/*")); rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get()); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); rule.assertBuildStatusSuccess(b); assertFile(true, "subfoo.txt", b); assertFile(false, "defaultexclude.txt", b); }
@Issue("JENKINS-16028") @Test public void testEnvDataInMavenProject() throws Exception { FreeStyleProject upstream = rule.createFreeStyleProject("upstream"); upstream.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar")); upstream.getPublishersList().add(new ArtifactArchiver("**/*", "", false, false)); FreeStyleBuild upstreamBuild = upstream.scheduleBuild2(0).get(); rule.assertBuildStatusSuccess(upstreamBuild); MavenModuleSet downstream = setupMavenJob(); downstream.getPrebuilders().add(CopyArtifactUtil.createRunSelector( "upstream", "", new BuildNumberRunSelector(Integer.toString(upstreamBuild.getNumber())), "**/*", "", "", false, false, false )); CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder(); downstream.getPrebuilders().add(envStep); MavenModuleSetBuild downstreamBuild = downstream.scheduleBuild2(0).get(); rule.assertBuildStatusSuccess(downstreamBuild); assertFile(true, "artifact.txt", downstreamBuild); assertEquals( Integer.toString(upstreamBuild.getNumber()), envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_UPSTREAM") ); }
@Issue("JENKINS-18762") @Test public void testEnvDataWrapped() throws Exception { FreeStyleProject upstream = rule.createFreeStyleProject("upstream"); upstream.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar")); upstream.getPublishersList().add(new ArtifactArchiver("**/*", "", false, false)); FreeStyleBuild upstreamBuild = upstream.scheduleBuild2(0).get(); rule.assertBuildStatusSuccess(upstreamBuild); FreeStyleProject downstream = rule.createFreeStyleProject(); downstream.getBuildersList().add(new WrapperBuilder(CopyArtifactUtil.createRunSelector( "upstream", "", new BuildNumberRunSelector(Integer.toString(upstreamBuild.getNumber())), "**/*", "", "", false, false, false ))); CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder(); downstream.getBuildersList().add(envStep); FreeStyleBuild downstreamBuild = downstream.scheduleBuild2(0).get(); rule.assertBuildStatusSuccess(downstreamBuild); assertFile(true, "artifact.txt", downstreamBuild); assertEquals( Integer.toString(upstreamBuild.getNumber()), envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_UPSTREAM") ); }
@Test public void testRelative() throws Exception { MockFolder folder = rule.jenkins.createProject(MockFolder.class, "folder"); FreeStyleProject other = folder.createProject(FreeStyleProject.class, "foo"); other.getBuildersList().add(new ArtifactBuilder()); other.getPublishersList().add(new ArtifactArchiver("**", "", false, false)); FreeStyleProject p = createProject("folder/foo", null, "", "", true, false, false, true); rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get()); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); rule.assertBuildStatusSuccess(b); assertFile(true, "foo.txt", b); }
@Test public void testAbsolute() throws Exception { MockFolder folder = rule.jenkins.createProject(MockFolder.class, "folder"); FreeStyleProject other = folder.createProject(FreeStyleProject.class, "foo"); other.getBuildersList().add(new ArtifactBuilder()); other.getPublishersList().add(new ArtifactArchiver("**", "", false, false)); FreeStyleProject p = createProject("/folder/foo", null, "", "", true, false, false, true); rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get()); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); rule.assertBuildStatusSuccess(b); assertFile(true, "foo.txt", b); }
@Test public void testAbsoluteFromFolder() throws Exception { FreeStyleProject other = rule.jenkins.createProject(FreeStyleProject.class, "foo"); other.getBuildersList().add(new ArtifactBuilder()); other.getPublishersList().add(new ArtifactArchiver("**", "", false, false)); MockFolder folder = rule.jenkins.createProject(MockFolder.class, "folder"); FreeStyleProject p = folder.createProject(FreeStyleProject.class, "bar"); p.getBuildersList().add(CopyArtifactUtil.createRunSelector("/foo", null, new StatusRunSelector(StatusRunSelector.BuildStatus.STABLE), "", "", false, false, true)); rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get()); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); rule.assertBuildStatusSuccess(b); assertFile(true, "foo.txt", b); }
@Test public void testRelativeFromFolder() throws Exception { FreeStyleProject other = rule.jenkins.createProject(FreeStyleProject.class, "foo"); other.getBuildersList().add(new ArtifactBuilder()); other.getPublishersList().add(new ArtifactArchiver("**", "", false, false)); MockFolder folder = rule.jenkins.createProject(MockFolder.class, "folder"); FreeStyleProject p = folder.createProject(FreeStyleProject.class, "bar"); p.getBuildersList().add(CopyArtifactUtil.createRunSelector("../foo", null, new StatusRunSelector(StatusRunSelector.BuildStatus.STABLE), "", "", false, false, true)); rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get()); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); rule.assertBuildStatusSuccess(b); assertFile(true, "foo.txt", b); }
public static void archiveArtifacts(BuildContext context, String filePattern) throws IOException, InterruptedException { context.listener.getLogger().println("Archiving artifacts matching: '" + filePattern + "'"); final Result resultBefore = context.build.getResult(); ArtifactArchiver task = new ArtifactArchiver(filePattern, "", true, false); task.perform(context.build, context.launcher, context.listener); final Result resultAfter = context.build.getResult(); context.listener.getLogger().println(" Artifacts archived finished. Status: " + resultAfter); if (isResultWorse(resultBefore, resultAfter)) { context.listener.getLogger().println(" Artifacts archive changed build status changed to " + resultAfter); } }
private FreeStyleProject createArtifactProject(String name) throws IOException { FreeStyleProject p = name != null ? rule.createFreeStyleProject(name) : rule.createFreeStyleProject(); p.getBuildersList().add(new ArtifactBuilder()); p.getPublishersList().add(new ArtifactArchiver("**", "", false, false)); return p; }
@Test public void testEmptyArtifactPublisher() throws Exception { FreeStyleProject project = j.createFreeStyleProject(); project.getPublishersList().add(new ArtifactArchiver("","",false)); assertTrue(checker.executeCheck(project)); }
@Test public void testArtifactPublisher() throws Exception { FreeStyleProject project = j.createFreeStyleProject(); project.getPublishersList().add(new ArtifactArchiver("something","",false)); assertFalse(checker.executeCheck(project)); }
@Test public void testPublisherJob() throws Exception { FreeStyleProject project = j.createFreeStyleProject(); project.getPublishersList().add(new ArtifactArchiver("","",false)); assertTrue(checker.executeCheck(project)); }
@Test public void testPublisherJob() throws Exception { FreeStyleProject project = j.createFreeStyleProject(); project.getPublishersList().add(new ArtifactArchiver("","",false)); assertFalse(checker.executeCheck(project)); }