How to associate a new page to a link on Jenkins

914 views
Skip to first unread message

MaxiTrompe

unread,
Apr 20, 2012, 6:21:34 AM4/20/12
to jenkin...@googlegroups.com
Hello,

I am developing a plugin for Jenkins that consists in adding a link to
the left sidebar of the main page and displaying information on a new
page when this one is selected.

To start my plugin, I took the Sidebar-Link Plugin (https://
wiki.jenkins-ci.org/display/JENKINS/Sidebar-Link+Plugin), which adds
links on the left side of the main page. My problem is that this
plugin only adds new links, but do not redirect to a new page.

I have found another plugin, Log Parser Plugin (https://wiki.jenkins-
ci.org/display/JENKINS/Log+Parser+Plugin), that I know creates new
pages. Unfortunately, the Log Parser Plugin is too complicated and I
did not find an anwser by examining it.

I have looked for such anwsers on the internet but there aren't much
information that helps.

If someone has any ideas of doing such, I would very much appreciate a
little help.

Thank you in advance

Vojtech Juranek

unread,
Apr 20, 2012, 7:16:12 AM4/20/12
to jenkin...@googlegroups.com

Hi,

all you have to do is to add

implements RootAction

to your class (which is also marked by @Extension annotation) and implement

public String getUrlName() method with returns correct URL of the page you want to display.

HTH

Vojta

MaxiTrompe

unread,
Apr 20, 2012, 7:29:53 AM4/20/12
to jenkin...@googlegroups.com
Yes, this is what I have already done: I have a class RootAction that return a url for a new page, but when I click on it, I have the following error
 

404 Not Found

Stapler processed this HTTP request as follows, but couldn't find the resource to consume the request

-> evaluate(<hudson.model.Hudson@1299db6> :hudson.model.Hudson,"/dummyurl")
-> evaluate(((StaplerProxy)<hudson.model.Hudson@1299db6>).getTarget(),"/dummyurl")
-> evaluate(<hudson.model.Hudson@1299db6>.getDynamic("dummyurl",...),"")
-> evaluate(<hudson.plugins.sidebar_link.LinkAction@ebb788> :hudson.plugins.sidebar_link.LinkAction,"")
-> No matching rule was found on <hudson.plugins.sidebar_link.LinkAction@ebb788> for ""

<hudson.plugins.sidebar_link.LinkAction@ebb788> has the following URL mappings, in the order of preference:

  1. TOKEN.groovy for url=/TOKEN/...
  2. VIEW.jelly for url=/VIEW
  3. hudson.plugins.sidebar_link.LinkAction.getIconFileName() for url=/iconFileName/...
  4. hudson.plugins.sidebar_link.LinkAction.getUrlName() for url=/urlName/...
  5. hudson.plugins.sidebar_link.LinkAction.getDisplayName() for url=/displayName/...
  6. java.lang.Object.getClass() for url=/class/...

MaxiTrompe

unread,
Apr 20, 2012, 7:36:37 AM4/20/12
to jenkin...@googlegroups.com
The thing is, I want the link to point to a new page that I can edit within my plugin

Vojtech Juranek

unread,
Apr 20, 2012, 10:09:05 AM4/20/12
to jenkin...@googlegroups.com

getUrlName() can return existing links or do the mapping of given object to URL, see Action javadoc [1] for details.

 

Probably the most easy way how to display something is e.g. this:

 

@Extension

public class DataPlotRoot implements RootAction {

 

public String getIconFileName() {

return "/plugin/data-processing-plugin/img/x-office-presentation.png";

}

 

public String getDisplayName() {

return "Data processing";

}

public String getUrlName() {

return "data-processing";

}

}

 

and in put into (applies for plugin org.jenkinsci.plugins.dataprocessing) src/main/resources/org/jenkinsci/plugins/dataprocessing/DataPlotRoot/

file called index.jelly

Content of this file will be shown when you click the link.

 

[1] http://javadoc.jenkins-ci.org/hudson/model/Action.html#getUrlName()

MaxiTrompe

unread,
Apr 20, 2012, 10:53:26 AM4/20/12
to jenkin...@googlegroups.com
Thank you very much, it works perfectly!
 
 

MaxiTrompe

unread,
Apr 23, 2012, 4:58:43 AM4/23/12
to jenkin...@googlegroups.com
Hello again,
I come back to this topic because after creating this new page successfully to my main page, I have encountered problems when I wanted to modify it.
 
The thing is I want to be able to display specific data into my new page, depending on the instance of jenkins.
 
I have tried to modify directly the file from my plugin, but the file seems inaccessible.
I have tried to include an html file in an accessible directory into the jelly, but the directory that I have to enter in the jelly is the full path from my computer, which will not be accessible when my plugin is finished.
 
If anyone knows how I could do something like that, it would be great.
Reply all
Reply to author
Forward
0 new messages