Skip to content

Commit

Permalink
[FIXED JENKINS-19764] Ensure parent dir of new builds dir exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck committed Aug 21, 2014
1 parent fd77294 commit 7f4014c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/main/java/hudson/model/Job.java
Expand Up @@ -619,6 +619,9 @@ public void renameTo(String newName) throws IOException {
super.renameTo(newName);
File newBuildDir = getBuildDir();
if (oldBuildDir.isDirectory() && !newBuildDir.isDirectory()) {
if (!newBuildDir.getParentFile().isDirectory()) {
newBuildDir.getParentFile().mkdirs();
}
if (!oldBuildDir.renameTo(newBuildDir)) {
throw new IOException("failed to rename " + oldBuildDir + " to " + newBuildDir);
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -2014,6 +2014,11 @@ public String getRawBuildsDir() {
return buildsDir;
}

@Restricted(NoExternalUse.class)
public void setRawBuildsDir(String buildsDir) {
this.buildsDir = buildsDir;
}

public FilePath getRootPath() {
return new FilePath(getRootDir());
}
Expand Down
8 changes: 8 additions & 0 deletions test/src/test/java/hudson/model/JobTest.java
Expand Up @@ -277,4 +277,12 @@ private static void tryConfigDotXml(JenkinsRule.WebClient wc, int status, String
}).intValue());
}

@Bug(19764)
@Test public void testRenameWithCustomBuildsDirWithSubdir() throws Exception {
j.jenkins.setRawBuildsDir("${JENKINS_HOME}/builds/${ITEM_FULL_NAME}/builds");
final FreeStyleProject p = j.createFreeStyleProject();
p.scheduleBuild2(0).get();
p.renameTo("different-name");
}

}

0 comments on commit 7f4014c

Please sign in to comment.