Skip to content
Permalink
Browse files

Merge pull request #52 from ikedam/feature/JENKINS-25155_FixNpeWithPr…

…omotedBuilds

[JENKINS-25155] Fix NPE with Promoted Builds
  • Loading branch information...
ikedam committed Oct 20, 2014
2 parents 836b307 + 56a184f commit 99d0e4f081e65bbacce6cfc400650206bb2f5ce8
Showing with 14 additions and 5 deletions.
  1. +14 −5 src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
@@ -373,11 +373,7 @@ private boolean canReadFrom(Job<?, ?> job, AbstractBuild<?, ?> build) {

// retrieve the "folder" (jenkins root if no folder used) for this build
private ItemGroup getItemGroup(AbstractBuild<?, ?> build) {
ItemGroup group = build.getProject().getParent();
if (group instanceof Job) {
// MatrixProject, MavenModuleSet, IvyModuleSet or comparable
return ((Job) group).getParent();
}
ItemGroup group = build.getProject().getRootProject().getParent();
return group;

}
@@ -509,6 +505,19 @@ private void add(ItemGroup ctx, String projectName, int buildNumber) {
// Use full name if configured with absolute path
// and relative otherwise
projectName = projectName.startsWith("/") ? item.getFullName() : item.getRelativeNameFrom(ctx);
if (projectName == null) {
// this is a case when the copying project doesn't belong to Jenkins item tree.
// (e.g. promotion for Promoted Builds plugin)
LOGGER.log(
Level.WARNING,
"Failed to calculate a relative path of {0} from {2}",
new Object[] {
item.getFullName(),
ctx.getFullName(),
}
);
return;
}
data.put("COPYARTIFACT_BUILD_NUMBER_"
+ projectName.toUpperCase().replaceAll("[^A-Z]+", "_"), // Only use letters and _
Integer.toString(buildNumber));

0 comments on commit 99d0e4f

Please sign in to comment.
You can’t perform that action at this time.