Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-21624] Misconfiguration leads to error.
If the "Attached archived artifacts" option is selected, but no
artifacts are configured to be archived by the job, the upload
fails with a `NullPointerException`.

Instead, we should detect that case and log a message indicating
that nothing is going to be uploaded.
  • Loading branch information
Joe Hansche committed Feb 3, 2014
1 parent 663b62c commit d7e9c4f
Showing 1 changed file with 21 additions and 9 deletions.
Expand Up @@ -194,9 +194,15 @@ protected List<RemoteAttachment> performAttachments(AbstractBuild<?, ?> build, L

if (this.attachArchivedArtifacts) {
final List<FilePath> archived = this.findArtifacts(build.getArtifactsDir());
log(listener, "Found " + archived.size()
+ " archived artifact(s) to upload to Confluence...");
files.addAll(archived);

if (archived.size() == 0) {
log(listener, "Attempting to attach the archived artifacts, but there are no"
+ " archived artifacts from the job! Check job configuration...");
} else {
log(listener, "Found " + archived.size()
+ " archived artifact(s) to upload to Confluence...");
files.addAll(archived);
}
}

final String fileSet = hudson.Util.fixEmptyAndTrim(this.fileSet);
Expand Down Expand Up @@ -502,12 +508,18 @@ private String performEdits(final AbstractBuild<?, ?> build, final BuildListener
private List<FilePath> findArtifacts(File artifactsDir) {
ArrayList<FilePath> files = new ArrayList<FilePath>();

if (artifactsDir != null) {
for (File f : artifactsDir.listFiles()) {
if (f.isDirectory()) {
files.addAll(findArtifacts(f));
} else if (f.isFile()) {
files.add(new FilePath(f));
if (artifactsDir != null && artifactsDir.isDirectory()) {
File[] listed = artifactsDir.listFiles();

if (listed != null) {
for (File f : listed) {
if (f == null) continue;

if (f.isDirectory()) {
files.addAll(findArtifacts(f));
} else if (f.isFile()) {
files.add(new FilePath(f));
}
}
}
}
Expand Down

0 comments on commit d7e9c4f

Please sign in to comment.