From 8eed4b2af43fa8bddb8a5d8fdd62288732cc7b60 Mon Sep 17 00:00:00 2001 From: Sven Schott Date: Fri, 6 Oct 2017 14:42:00 +1100 Subject: [PATCH] Add checkbox for Builder to fail deployment when there are no artifacts. --- .../ArtifactDeployerBuilder.java | 29 +++++++++++++++++++ .../ArtifactDeployerBuilder/config.jelly | 6 ++++ 2 files changed, 35 insertions(+) diff --git a/src/main/java/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerBuilder.java b/src/main/java/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerBuilder.java index af0d944..3f72005 100644 --- a/src/main/java/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerBuilder.java +++ b/src/main/java/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerBuilder.java @@ -126,10 +126,39 @@ private Map> processDeployment(final AbstractB ArtifactDeployerManager deployerManager = new ArtifactDeployerManager(); FilePath basedirFilePath = deployerManager.getBasedirFilePath(workspace, basedir); List results = basedirFilePath.act(deployerCopy); + + if (isFailNoFilesDeploy(results, entry)) { + throw new ArtifactDeployerException("Can't find any artifacts to deploy with the following configuration :" + + printConfiguration(includes, excludes, basedirFilePath.getRemote(), outputPath)); + } + deployedArtifacts.put(entry.getUniqueId(), results); return deployedArtifacts; } + private boolean isFailNoFilesDeploy(List results, ArtifactDeployerEntry entry) { + return ((results == null || results.size() == 0) && entry.isFailNoFilesDeploy()); + } + + private String printConfiguration(String includes, String excludes, String basedir, String outputPath) { + StringBuffer sb = new StringBuffer(); + + if (includes != null) { + sb.append(",includes:").append(includes); + } + if (excludes != null) { + sb.append(",excludes:").append(excludes); + } + + sb.append(",basedir:").append(basedir); + sb.append(",outPath:").append(outputPath); + sb.append("]"); + + sb = sb.replace(0, 1, "["); + + return sb.toString(); + } + @SuppressWarnings("unused") public ArtifactDeployerEntry getEntry() { return entry; diff --git a/src/main/resources/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerBuilder/config.jelly b/src/main/resources/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerBuilder/config.jelly index bef47dd..9ba6ab8 100644 --- a/src/main/resources/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerBuilder/config.jelly +++ b/src/main/resources/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerBuilder/config.jelly @@ -49,6 +49,12 @@ THE SOFTWARE. + + + + +