Nevermind on "Note" above.. I found that while that code worked, it left
exceptions in the console.. stapler still tried to send a 404 (since I return
null) even though I already sent a redirect.. better way:
Index: core/src/main/java/hudson/model/Run.java
===================================================================
— core/src/main/java/hudson/model/Run.java (revision 14038)
+++ core/src/main/java/hudson/model/Run.java (working copy)
@@ -1271,4 +1271,21 @@
return Mailer.DESCRIPTOR.getAdminAddress();
}
}
+
+ @Override
+ public Object getDynamic(String token, StaplerRequest req, StaplerResponse
rsp)
{
+ Object result = super.getDynamic(token, req, rsp);
+ if (result == null)
+ // Next/Previous Build links on an action page (like
/job/Abc/123/testReport)
+ // will also point to same action (/job/Abc/124/testReport), but
other builds
+ // may not have the action.. rather than 404, redirect up to the
build page.
+ result = new RedirectUp();
+ return result;
+ }
+
+ public static class RedirectUp {
+ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws
IOException
{
+ rsp.sendRedirect("..");
+ }
+ }
}
I'm going to go ahead and commit this.. let me know if you think it needs any
rework.
This could be implemented to automatically jump back up to the build page..
Index: core/src/main/java/hudson/model/Run.java
{ + Object result = super.getDynamic(token, req, rsp); + if (result == null) + rsp.sendRedirect(".."); + return result; + }===================================================================
— core/src/main/java/hudson/model/Run.java (revision 14038)
+++ core/src/main/java/hudson/model/Run.java (working copy)
@@ -1271,4 +1271,12 @@
return Mailer.DESCRIPTOR.getAdminAddress();
}
}
+
+ @Override
+ public Object getDynamic(String token, StaplerRequest req, StaplerResponse
rsp) throws IOExcept
ion
}
Then /job/Abc/123/someReport will automatically go to /job/Abc/123 if that build
doesn't have "someReport". How does this sound?
Note: I put "throws IOException" in the code above.. to use that, I'd also need
to add throws IOException in the parent Actionable.getDynamic, and in several
other classes that override this method and call super. Let me know if you'd
prefer I just catch/ignore IOException in Run.getDynamic.
Looking for a response before I commit or rework this one.. thanks.