Next, we need to make the action we’re storing with the build visible.
First, we need to go back to the HelloWorldAction
and define an icon, title, and URL name:
@Override
public String getIconFileName() {
return "document.png"; (1)
}
@Override
public String getDisplayName() {
return "Greeting"; (2)
}
@Override
public String getUrlName() {
return "greeting"; (3)
}
1 |
This is the icon used for the side panel item. document.png is one of the predefined icons bundled with Jenkins. |
2 |
This is the label used for the side panel item. |
3 |
This is the URL fragment used for this action. |
With these changes, the action will show in the build’s side panel, and link to the URL \http://JENKINS/job/JOBNAME/BUILDNUMBER/greeting/
.
Next, the page appearing at that URL needs to be defined.
To create such views in Jenkins, Apache Commons Jelly is typically used.
Jelly allows defining XML and XHTML output in XML.
It has many features useful for this purpose: It:
-
supports conditions and loops
-
allows inclusion of view fragments defined elsewhere
-
can be used to define reusable UI components
In the directory src/main/resources/io/jenkins/plugins/sample/
, we need to create a new directory called HelloWorldAction/
.
This directory corresponds to the HelloWorldAction
class and contains related resources.
|
This is a directory in src/main/resources , not src/main/java .
|
|
We can see that resources related to the build step HelloWorldBuilder are stored in the src/main/resources/io/jenkins/plugins/sample/HelloWorldBuilder/ directory:
config.jelly is the build step configuration form,
the various config*.properties files contain the localizations for the build step configuration
and the help*.html files provide the localized inline help for the configuration.
|
Create a file named index.jelly
in src/main/resources/io/jenkins/plugins/sample/HelloWorldAction/
.
This will be what gets shown at the \http://JENKINS/job/JOBNAME/BUILDNUMBER/greeting/
URL.
Add the following content:
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:st="jelly:stapler">
<l:layout title="Greeting"> (1)
<l:main-panel> (2)
<h1> (3)
Name: ${it.name} (4)
</h1>
</l:main-panel>
</l:layout>
</j:jelly>
1 |
layout is a reusable tag defined in Jenkins core that provides the basic page layout with header, side panel, main content area, and footer. |
2 |
To make the name show up in the main content area (rather than e.g. the side panel), we need to wrap our output in a main-panel tag. |
3 |
We can use any HTML tags and they will be used for the output. |
4 |
This is a JEXL expression. it refers to the Java object the view belongs to (similar to this in Java), in this case the HelloWorldAction instance. it.name is equivalent to a getter call (getName() ). |
The resulting page will look similar to this: