Advice for handling multiple artifacts on a single Build Action

860 views
Skip to first unread message

Chris Price

unread,
May 15, 2013, 12:17:19 PM5/15/13
to jenkin...@googlegroups.com
Hello,

I'm working on a plugin that archives multiple artifacts (directories of html and content) on each build.  I have this part working without any big problems.

However, I'm struggling a bit with the code to expose these artifacts in the Jenkins UI.  What I want to do is to use DirectoryBrowserSupport to render the artifact html, and this works fine when I do it from a static URL path that is appended on to my Action's URL; e.g.: /myplugin/artifact.

The problem is that, since I have multiple artifacts per build, the URL needs to contain an extra token to identify which artifact we're retrieving:

/myplugin/artifacts/ARTIFACT_ID

I've implemented a "doArtifacts" method that can successfully map these kinds of request to the appropriate paths for the artifacts on disk, but when I try to use DirectoryBrowserSupport in this context, it breaks because the extra token "ARTIFACT_ID" is still included in the value of "request.getRestOfPath()", so DirectoryBrowserSupport is looking for paths that begin with that prefix inside of the directory I've specified on disk, and those paths don't exist.

I'm working around this for now with some gross code that looks like this:

                RequestImpl reqImpl = (RequestImpl)request;
        reqImpl.tokens.next();

Which allows me to advance the token index inside of the request object before I construct my DirectoryBrowserSupport.  This works perfectly, but I'm obviously stepping outside of the bounds of the supported API here and worry that it could break in a future release.

Anyone have any suggestions on a cleaner way to solve this?  Pointer to relevant source code in an existing plugin would be just fine too!

Thanks!
Chris

Jesse Glick

unread,
May 15, 2013, 1:50:42 PM5/15/13
to jenkin...@googlegroups.com
On 05/15/2013 12:17 PM, Chris Price wrote:
> I've implemented a "doArtifacts" method that can successfully map these kinds of request to the appropriate paths for the artifacts on disk, but when I try to use
> DirectoryBrowserSupport in this context, it breaks because the extra token "ARTIFACT_ID" is still included in the value of "request.getRestOfPath()", so
> DirectoryBrowserSupport is looking for paths that begin with that prefix inside of the directory I've specified on disk, and those paths don't exist.

Maybe try adding a getArtifacts method returning an object with a getDynamic method which in turn calls DirectoryBrowserSupport?

Chris Price

unread,
May 15, 2013, 2:17:45 PM5/15/13
to jenkin...@googlegroups.com
Oh, interesting, so if I use "getBlah" instead of "doBlah" then it will call methods on the inner object?  Didn't know that.  Thanks!




--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Jesse Glick

unread,
May 15, 2013, 2:55:32 PM5/15/13
to jenkin...@googlegroups.com

Chris Price

unread,
May 15, 2013, 3:04:31 PM5/15/13
to jenkin...@googlegroups.com
Thanks, Jesse.  I was looking all over for something that documented that stuff and just didn't have any luck finding it... this is immensely helpful!


On Wed, May 15, 2013 at 11:55 AM, Jesse Glick <jgl...@cloudbees.com> wrote:
http://stapler.kohsuke.org/reference.html
Reply all
Reply to author
Forward
0 new messages