Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED JENKINS-29989] Update RunIdMigrator to properly handle matrix and Maven jobs #1802

Merged
merged 3 commits into from Aug 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment now on line 369 should be edited to clarify that the older clause handles grandchildren from getRootDirFor whereas this clause handles direct children.

// 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>");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move such strings to resources in future

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