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="https://planets.datenkollektiv.de/">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') {
    description("""
<h3>Planets builds</h3>
<h3>Homepage</h3>
Plain Java builds are running inside the main Jenkins container.
<h3>Android</h3>
Android artefacts are built inside a Docker container with the required Android SDK.
<h3>Overview</h3>
<ul>
<li><a href="https://planets.datenkollektiv.de">Planets Homepage</a></li>
<li><a href="https://devops.datenkollektiv.de/pages/planets.html">Datenkollektiv Blog / Planets</a></li>
</ul>
""")
    jobs {
        names('Planets homepage', 'Planets Spaceship')
    }
    columns {
        status()
        weather()
        name()
        lastSuccess()
        lastFailure()
        lastDuration()
        buildButton()
    }
}

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

pipelineJob("Planets homepage") {
    description("""
<h3>Planets homepage: <a href="https://planets.datenkollektiv.de">https://planets.datenkollektiv.de</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