Skip to content
Permalink
Browse files

[FIXED JENKINS-25155] Fix NPE with Promoted Builds: should use getRoo…

…tProject() to get the parent builds of matrix, maven, ivy. Item#getRelativeNameFrom may return null.
  • Loading branch information...
ikedam committed Oct 19, 2014
1 parent 836b307 commit 56a184f021bf9a81a072607466156d4c3e4996ec
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 56a184f

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