Skip to content

Commit

Permalink
Merge pull request #52 from ikedam/feature/JENKINS-25155_FixNpeWithPr…
Browse files Browse the repository at this point in the history
…omotedBuilds

[JENKINS-25155] Fix NPE with Promoted Builds
  • Loading branch information
ikedam committed Oct 20, 2014
2 parents 836b307 + 56a184f commit 99d0e4f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
Expand Up @@ -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;

}
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 99d0e4f

Please sign in to comment.