Groovy Postbuild Plugin

Plugin Information

Plugin ID groovy-postbuild
Latest Release 1.9-h-2
Latest Release Date Oct 24, 2013
Plugin Central Plugin Central 3.2
Sources Github
Support Eclipse Hudson Forum
Issue Tracking Eclipse Bugzilla
Hudson Core (latest) 3.3.3

This plugin executes a groovy script in the Hudson JVM. Typically, the script checks some conditions and changes accordingly the build result, puts badges next to the build in the build history and/or displays information on the build summary page.


The groovy script can use the variable manager, which provides access to the following objects and methods:

  • contains(file, regexp) - returns true if the given file contains a line matching regexp.
  • logContains(regexp) - returns true if the build log file contains a line matching regexp.
  • getMatcher(file, regexp) - returns a java.util.regex.Matcher for the first occurrence of regexp in the given file.
  • getLogMatcher(regexp) - returns a java.util.regex.Matcher for the first occurrence of regexp in the build log file.
  • setBuildNumber(number) - sets the build with the given number as current build. The current build is the target of all methods that add or remove badges and summaries or change the build result.
  • addShortText(text) - puts a badge with a short text, using the default format.
  • addShortText(text, color, background, border, borderColor) - puts a badge with a short text, using the specified format.
  • addBadge(icon, text) - puts a badge with the given icon and text. In addition to the 16x16 icons offered by Hudson, groovy-postbuild provides the following icons:

    - completed.gif
    - db_in.gif
    - db_out.gif
    - delete.gif
    - error.gif
    - folder.gif
    - green.gif
    - info.gif
    - red.gif
    - save.gif
    - success.gif
    - text.gif
    - warning.gif
    - yellow.gif

  • addInfoBadge(text) - puts a badge with info icon and the given text.
  • addWarningBadge(text) - puts a badge with warning icon and the given text.
  • addErrorBadge(text) - puts a badge with error icon and the given text.
  • removeBadges() - removes all badges from the current build.
  • removeBadge(index) - removes the badge with the given index.
  • createSummary(icon) - creates an entry in the build summary page and returns a summary object corresponding to this entry. The icon must be one of the 48x48 icons offered by Hudson. You can append text to the summary object by calling its appendText methods:
    • appendText(text, escapeHtml)
    • appendText(text, escapeHtml, bold, italic, color)
  • removeSummaries() - removes all summaries from the current build.
  • removeSummary(index) - removes the summary with the given index.
  • buildUnstable() - sets the build result to UNSTABLE.
  • buildFailure() - sets the build result to FAILURE.
  • buildSuccess() - sets the build result to SUCCESS.

It is also possible to delete badges and summaries by using the following links:

  • remove all badges:
    • http://your-hudson/job/your-job/build-number/parent/parent/plugin/groovy-postbuild/removeBadges
  • remove all summaries:
    • http://your-hudson/job/your-job/build-number/parent/parent/plugin/groovy-postbuild/removeSummaries
  • remove the badge with the given index:
    • http://your-hudson/job/your-job/build-number/parent/parent/plugin/groovy-postbuild/removeBadge?index=idx
  • remove the summary with the given index:
    • http://your-hudson/job/your-job/build-number/parent/parent/plugin/groovy-postbuild/removeSummary?index=idx

Example 1

The script below puts a warning badge and mark the build as unstable if it detects that deprecated methods were used.

if(manager.logContains(".*uses or overrides a deprecated API.*")) {
    manager.addWarningBadge("Thou shalt not use deprecated methods.")
    manager.createSummary("warning.gif").appendText("<h1>You have been warned!</h1>", false, false, false, "red")

Example 2

Suppose we have a parameterized build, which uses the boolean parameter storeToDB in order to instruct the build to store some artifacts into the database. The script below puts a badge next to the builds for which this parameter is set.

if("true".equals("storeToDB"))) {
    manager.addBadge("db_in.gif", "Stored to DB")

Example 3

Suppose we have a parameterized build, which uses the string parameter version. The script below puts a short text indicating the value of this parameter next to successful and unstable builds.

if( {

Example 4

The script below determines how long it took to build the project and displays the corresponding value as a short text next to each build.

def matcher = manager.getMatcher(, "^Total time: (.*)\$")
if(matcher?.matches()) {
    manager.addShortText(, "grey", "white", "0px", "white")

Example 5

For badges, you can choose from the 16x16 icons provided by Hudson or from the icons provided by this plugin. Some of the names of groovy-postbuild icons conflict with the names of Hudson icons (e.g. yellow.gif). For these icons, you have to provide the complete path (e.g. /images/16x16/yellow.gif), in case you want a badge with the Hudson icon. You can also use icons provided by other plugins (e.g. Green Balls), by specifying the complete path to the icon.

manager.addBadge("star-gold.gif", "icon from Hudson")
manager.addBadge("yellow.gif", "icon from groovy-postbuild plugin")
manager.addBadge("/images/16x16/yellow.gif", "icon from Hudson")
manager.addBadge("/plugin/greenballs/16x16/green.gif", "icon from greenballs plugin")

Example 6

The script below displays on the build summary page all classes that use Sun proprietary API.

pattern = ~/.*src\/main\/java\/(.*)\.java:[^ ]* (.*) is Sun proprietary API and may be removed in a future release.*/
def map = [:] { line ->
    matcher = pattern.matcher(line)
    if(matcher.matches()) {
        ownClass ="/", ".")
        sunClass =
        map[ownClass] = sunClass
if(map.size() > 0) {
    summary = manager.createSummary("warning.gif")
    summary.appendText("Classes using Sun proprietary API:<ul>", false)
    map.each {
        summary.appendText("<li><b>$it.key</b> - uses $it.value</li>", false)
    summary.appendText("</ul>", false)

Example 7

The script below removes all badges and summaries from previous builds.

currentBuildNumber =
for(i=1; i<currentBuildNumber; i++) {
    if(manager.setBuildNumber(i)) {

Example 8

The script below marks the running build as deployed and the previous build as undeployed.

manager.createSummary("gear2.gif").appendText("<h2>Successfully deployed</h2>", false)

currentBuildNumber =
if(manager.setBuildNumber(currentBuildNumber - 1)) {
   actions =
    actions.each { action ->
        if (action.metaClass.hasProperty(action, "text") && action.text.contains("deployed")) {
    currDate = new Date().dateTimeString
    manager.addShortText("undeployed: $currDate", "grey", "white", "0px", "white")
    manager.createSummary("gear2.gif").appendText("<h2>Undeployed: $currDate</h2>", false, false, false, "grey")

Example 9 (thanks to Ken Bertelson)

The script below changes the description of the first failed test.

def tr =
def cr = tr.failedTests.get(0)
cr.description = "My CaseResult desc"


plugin-post-build plugin-post-build Delete
Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.