Adding Views and Descriptions to Jenkins - The Groovy Way

By default Jenkins doesn’t allow HTML markup in descriptions. This is the first thing we have to change to go for nice descriptions.

Enable HTML for View and Job descriptions

import hudson.markup.RawHtmlMarkupFormatter

Jenkins.instance.setMarkupFormatter(new RawHtmlMarkupFormatter(false))

Let’s start with the main page of our Jenkins instance: Add a description to the All view:

import org.kohsuke.stapler.StaplerRequest
import org.kohsuke.stapler.StaplerResponse

Jenkins.get().getView('All').doSubmitDescription([ getParameter: { return """
<h3>Welcome to datenkollektiv Jenkins</h3>
This Jenkins builds all required components to power <a href="">Planets</a>
"""; }] as StaplerRequest, [ sendRedirect: { return; } ] as StaplerResponse)

This one was easy: How to set a Views description in Groovy

We create our other views with listView()

// create views
listView('Planets') {
<h3>Planets builds</h3>
Plain Java builds are running inside the main Jenkins container.
Android artefacts are built inside a Docker container with the required Android SDK.
<li><a href="">Planets Homepage</a></li>
<li><a href="">Datenkollektiv Blog / Planets</a></li>
    jobs {
        names('Planets homepage', 'Planets Spaceship')
    columns {

Next step is to add informative description to the build Jobs themselves:

pipelineJob("Planets homepage") {
<h3>Planets homepage: <a href=""></a></h3>
This build job automagically recreates the Docker container powering the Planets homepage.         


Nice description is technically not required, but I think adding such descriptions is a great improvement of our Jenkins setup.

If you got so far you might also like our other Jenkins related posts:

Programmatically add Environment Variables to a Jenkins Instance

How to Checkout a Gerrit Change in a Jenkins Sandbox Pipeline

How-To manipulate a Jenkins Job with the Script Console

Show Comments