diff --git a/core/src/main/java/hudson/tasks/ArtifactArchiver.java b/core/src/main/java/hudson/tasks/ArtifactArchiver.java index bd4d432fac..02137ad369 100644 --- a/core/src/main/java/hudson/tasks/ArtifactArchiver.java +++ b/core/src/main/java/hudson/tasks/ArtifactArchiver.java @@ -31,7 +31,6 @@ import hudson.AbortException; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; -import hudson.Functions; import hudson.Launcher; import hudson.Util; import hudson.model.AbstractBuild; @@ -272,10 +271,8 @@ public class ArtifactArchiver extends Recorder implements SimpleBuildStep { if (msg != null) { listener.getLogger().println(msg); } - } catch (FilePath.FileMaskNoMatchesFoundException e) { - listener.getLogger().println(e.getMessage()); } catch (Exception e) { - Functions.printStackTrace(e, listener.getLogger()); + LOG.log(Level.FINE, e, () -> "Failed to validate ant file mask."); } if (allowEmptyArchive) { listener.getLogger().println(Messages.ArtifactArchiver_NoMatchFound(artifacts)); diff --git a/test/src/test/java/hudson/tasks/ArtifactArchiverTest.java b/test/src/test/java/hudson/tasks/ArtifactArchiverTest.java index 92dee288b4..2157e89492 100644 --- a/test/src/test/java/hudson/tasks/ArtifactArchiverTest.java +++ b/test/src/test/java/hudson/tasks/ArtifactArchiverTest.java @@ -46,6 +46,7 @@ import hudson.model.FreeStyleProject; import hudson.model.Label; import hudson.model.Result; import hudson.model.Run; +import hudson.model.Slave; import hudson.remoting.VirtualChannel; import hudson.slaves.DumbSlave; import java.io.File; @@ -134,8 +135,48 @@ public class ArtifactArchiverTest { @Test @Issue("JENKINS-51913") public void testFileMaskNoMatchesFoundException() throws Exception { + hudson.FilePath.VALIDATE_ANT_FILE_MASK_BOUND = 1; FreeStyleProject project = j.createFreeStyleProject(); - String pattern = "dir/**"; + project.getBuildersList().replaceBy(Collections.singleton(new TestBuilder() { + @Override + public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { + FilePath dir = build.getWorkspace().child("dir"); + dir.child("file").write("content", "UTF-8"); + dir.child("file2").write("content", "UTF-8"); + dir.child("file3").write("content", "UTF-8"); + return true; + } + })); + + String pattern = "dir/*.log"; + ArtifactArchiver aa = new ArtifactArchiver(pattern); + aa.setAllowEmptyArchive(true); + project.getPublishersList().replaceBy(Collections.singleton(aa)); + FreeStyleBuild build = j.buildAndAssertSuccess(project); + assertFalse(project.getBuildByNumber(1).getHasArtifacts()); + j.assertLogContains("No artifacts found that match the file pattern \"" + pattern + "\"", build); + assertThat("No stacktrace shown", build.getLog(31), Matchers.iterableWithSize(lessThan(30))); + } + + @Test + @Issue("JENKINS-71700") + public void testFileMaskNoMatchesFoundExceptionOnAgent() throws Exception { + Slave agent = j.createOnlineSlave(); + hudson.FilePath.VALIDATE_ANT_FILE_MASK_BOUND = 1; + FreeStyleProject project = j.createFreeStyleProject(); + project.setAssignedNode(agent); + project.getBuildersList().replaceBy(Collections.singleton(new TestBuilder() { + @Override + public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { + FilePath dir = build.getWorkspace().child("dir"); + dir.child("file").write("content", "UTF-8"); + dir.child("file2").write("content", "UTF-8"); + dir.child("file3").write("content", "UTF-8"); + return true; + } + })); + + String pattern = "dir/*.log"; ArtifactArchiver aa = new ArtifactArchiver(pattern); aa.setAllowEmptyArchive(true); project.getPublishersList().replaceBy(Collections.singleton(aa));