Skip to content

Commit

Permalink
Merge pull request #1802 from jpederzolli/master
Browse files Browse the repository at this point in the history
[FIXED JENKINS-29989] Update RunIdMigrator to properly handle matrix and Maven jobs
  • Loading branch information
jglick committed Aug 21, 2015
2 parents ee7565e + 7795039 commit 3d7878f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/src/main/java/jenkins/model/RunIdMigrator.java
Expand Up @@ -350,6 +350,12 @@ private void unmigrateJobsDir(File jobs) throws Exception {
return;
}
for (File job : jobDirs) {

if (job.getName().equals("builds")) {
// Might be maven modules, matrix builds, etc. which are direct children of job
unmigrateBuildsDir(job);
}

File[] kids = job.listFiles();
if (kids == null) {
continue;
Expand All @@ -361,7 +367,8 @@ private void unmigrateJobsDir(File jobs) throws Exception {
if (kid.getName().equals("builds")) {
unmigrateBuildsDir(kid);
} else {
// Might be jobs, modules, promotions, etc.; we assume an ItemGroup.getRootDirFor implementation returns grandchildren.
// Might be jobs, modules, promotions, etc.; we assume an ItemGroup.getRootDirFor implementation
// returns grandchildren, unmigrateJobsDir(job) call above handles children.
unmigrateJobsDir(kid);
}
}
Expand Down
20 changes: 20 additions & 0 deletions core/src/test/java/jenkins/model/RunIdMigratorTest.java
Expand Up @@ -128,6 +128,26 @@ public class RunIdMigratorTest {
assertEquals("{1=→2014-01-02_03-04-05, 2014-01-02_03-04-05={build.xml='<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <number>1</number>\n <otherstuff>ok</otherstuff>\n</run>'}}", summarize());
}

@Test public void reverseMatrixAfterNewBuilds() throws Exception {
File root = dir;
dir = new File(dir, "jobs/someproject/Environment=prod/builds");
write("1/build.xml", "<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <timestamp>1388649845000</timestamp>\n <otherstuff>ok</otherstuff>\n</run>");
write("legacyIds", "");
assertEquals("{1={build.xml='<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <timestamp>1388649845000</timestamp>\n <otherstuff>ok</otherstuff>\n</run>'}, legacyIds=''}", summarize());
RunIdMigrator.main(root.getAbsolutePath());
assertEquals("{1=→2014-01-02_03-04-05, 2014-01-02_03-04-05={build.xml='<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <number>1</number>\n <otherstuff>ok</otherstuff>\n</run>'}}", summarize());
}

@Test public void reverseMavenAfterNewBuilds() throws Exception {
File root = dir;
dir = new File(dir, "jobs/someproject/test$test/builds");
write("1/build.xml", "<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <timestamp>1388649845000</timestamp>\n <otherstuff>ok</otherstuff>\n</run>");
write("legacyIds", "");
assertEquals("{1={build.xml='<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <timestamp>1388649845000</timestamp>\n <otherstuff>ok</otherstuff>\n</run>'}, legacyIds=''}", summarize());
RunIdMigrator.main(root.getAbsolutePath());
assertEquals("{1=→2014-01-02_03-04-05, 2014-01-02_03-04-05={build.xml='<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <number>1</number>\n <otherstuff>ok</otherstuff>\n</run>'}}", summarize());
}

// TODO test sane recovery from various error conditions

private void write(String file, String text) throws Exception {
Expand Down

0 comments on commit 3d7878f

Please sign in to comment.