View Groovy Postbuild on the plugin site for more information.
Older versions of this plugin may not be safe to use. Please review the following warnings before using an older version:
Migration from 1.X
From version 2.0, Groovy Postbuild plugin introduces Script Security Plugin.
Administrators can prevent users without proper privileges from running harmful scripts.
For details, see Script Security Plugin.
This doesn't affect Jenkins without security enabled and users with administrative privilege (to be exact, with RUN_SCRIPTS permission).
When you upgrade the Groovy Postbuild plugin from 1.X to 2.X, you and your Jenkins users
also requires update configurations of Groovy Postbuild, or they will fail with outputs like this:
Scripts using only whitelisted methods of manager
Scripts using only whitelisted methods of manager can run with using Groovy sandbox.
They can be validated only by checking "Use Groovy Sandbox".
Scripts using non-whitelisted methods
Scripts using non-whitelisted methods of manager or methods not of manager requires
approval of administrators.
Administrators should check and approve those scripts in Manage Jenkins > In-process Script Approval.
Scripts using external jar files
If you refer external jar files from your scripts, you need to have those jar files approved by administartors.
Administrators should check and approve those jar files in Manage Jenkins > In-process Script Approval.
Scripts using external class directories
Script Security Plugin doesn't support class directories.
If you refer external class directories from your scripts, you should archive them into jar files.
It can be performed by running a following command:
You can use /path/to/mylib.jar as an additonal classpath for scripts.
The groovy script can use the variable manager, which provides various methods to decorate your builds.
Those methods can be classified into whitelisted methods and non-whitelisted methods.
You can always use Whitelisted methods, but you can use Non-whitelisted methods only when "Enable groovy postbuild security" is not enabled (version 1.X) or in scripts approved by administrators (since version 2.x)
- getEnvVariable(key) - get a variable value. (since 1.10)
- getResult() - get a build result string (like SUCCESS, FAILURE) (since 2.2)
- logContains(regexp) - returns true if the build log file contains a line matching regexp.
- getLogMatcher(regexp) - returns a java.util.regex.Matcher for the first occurrence of regexp in the build log file.
- 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. For Colors supported, Google "html color names".
- addBadge(icon, text) - puts a badge with the given icon and text. In addition to the 16x16 icons offered by Jenkins, groovy-postbuild provides the following icons (watch out for duplicates, see Example 5):
- addBadge(icon, text, link) - like addBadge(icon, text), but the Badge icon then actually links to the given link (since 1.8)
- 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. It is often used with
- removeBadge(index) - removes the badge with the given index. It is often used with
- buildUnstable() - sets the build result to UNSTABLE.
- buildFailure() - sets the build result to FAILURE.
- buildSuccess() - sets the build result to SUCCESS.
- buildIsA(klass) - test the build is a specified class (since 2.0)
Methods returning non-primitive objects aren't whitelisted as groovy-postbuild doesn't ensure every methods of those objects are safe.
- hudson - the current Hudson instance (see hudson.model.Hudson).
- build - the current build (see hudson.model.AbstractBuild).
- listener - the build listener (see hudson.model.BuildListener).
envVars - the build variables map. You can get a variable value with
You shouldn't update values. This isn't whitelisted, and it is recommended to use
getEnvVariable(key)instead. (since 1.10)
- contains(file, regexp) - returns true if the given file contains a line matching regexp. Not whitelisted as it allows users access any files (for example, a file containing passwords).
- getMatcher(file, regexp) - returns a java.util.regex.Matcher for the first occurrence of regexp in the given 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.
- 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 Jenkins. You can append text to the summary object by calling its appendText methods. Be careful appending HTML-unescaped texts as they can be harmful.
- 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.
It is also possible to delete badges and summaries by using the following links:
- remove all badges:
- remove all summaries:
- remove the badge with the given index:
- remove the summary with the given index:
The script below puts a warning badge and mark the build as unstable if it detects that deprecated methods were used.
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.
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.
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.
For badges, you can choose from the 16x16 icons provided by Jenkins or from the icons provided by this plugin. Some of the names of groovy-postbuild icons conflict with the names of Jenkins 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 Jenkins icon. You can also use icons provided by other plugins (e.g. Green Balls), by specifying the complete path to the icon.
The script below displays on the build summary page all classes that use Sun proprietary API.
The script below removes all badges and summaries from previous builds.
The script below marks the running build as deployed and the previous build as undeployed.
Example 9 (thanks to Ken Bertelson)
The script below changes the description of the first failed test.
Example 10 (thanks to Frank Merrow)
Trivial, but hard to find the first time: Write a line to the job's Console Output:
To report a bug or request an enhancement to this plugin please create a ticket in JIRA (you need to login or to sign up for an account). Also have a look on How to report an issue
- Open Issues
- Bug report
- Request or propose an improvement of existing feature
- Request or propose a new feature
Version 2.4.3 (Nov 18, 2018)
Version 2.4.2 (Aug 8, 2018)
- FIX: removeBadge / removeBadges doesn't work (throw UnsupportedOperationException) (JENKINS-52043)
Version 2.4.1 (May 4, 2018)
- Have Build Monitor Plugin not to cause errors. (JENKINS-50420)
- Introduced fake
- The feature of build-monitor to cooperate with groovy-postbuild doesn't work yet. It requires the upcoming version of build-monitor plugin to have it work again.
- Introduced fake
Version 2.4 (Mar 25, 2018)
- Now built for Jenkins-2.60.3 and later
- Extract badge and summary features to (JENKINS-43992).
- You can use badge and summary features in pipeline only with badge-plugin. See Badge Plugin for more details.
- Sanitize HTML in the badges.
- You no longer be able to use HTML expressions in badge contents.
- Don't upgrade to this version if you use Build Monitor Plugin.
- Groovy-postbuild-2.4 breaks build-moitor-1.12 or earlier. Sorry.
- Please postpone upgrading groovy-postbuild till fixing this issue: JENKINS-50420
- No new features in groovy-postbuild-2.4, and you can use groovy-postbuild-2.3.1.
- You can downgrade your groovy-postbuild in the Jenkins Plugin Management page.
- You can download earlier versions of groovy-postbuild from "Archives" link in https://plugins.jenkins.io/groovy-postbuild
Some classes are migrated to badge-plugin. Please change classes in your codes if you access those classes:
Old Class New Class org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildAction com.jenkinsci.plugins.badge.action.BadgeAction org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildSummaryAction com.jenkinsci.plugins.badge.action.BadgeSummaryAction
Version 2.3.1 (Feb 7, 2016)
- Dependency to pipeline (aka. workflow) is optional (JENKINS-32589).
Version 2.3 (Dec 27, 2015)
- Now built for Jenkins-1.609 and later
- Supports workflow (JENKINS-26918)
- You can use
managerin workflow scripts.
- You can use
Version 2.2.2 (Oct 17, 2015)
- Added MIT License (JENKINS-21270)
Version 2.2.1 (Aug 18, 2015)
- Improved the behavior with Template Project Plugin (JENKINS-21276)
- Prior versions disturbed the execution of Template Project Plugin when the build was failed (even if the groovy script succeeded).
Version 2.2 (Dec 19, 2014)
- added getResult() as a whitelisted method (JENKINS-25738)
Version 2.1 (Oct 25, 2014)
- You can access other plugins in groovy scripts (JENKINS-14154)
Version 2.0 (Sep 21, 2014)
- Changed target Jenkins core from 1.466 to 1.509.4.
- Introduced Script Security Plugin. (JENKINS-15212)
- You need reconfigure your projects or approve scripts. Have a look at #Migration from 1.X
Version 1.10 (July 26, 2014)
Version 1.9 (April 29, 2014)
- JENKINS-21924 Support run for matrix parent
- change log level for each search from info to fine
Version 1.8 (August 22, 2012)
- JENKINS-13024 Error in log indicating a missing descriptor
- added clickable badge
- Changed required Jenkins version to 1.466
Version 1.7 (May 2, 2012)
- JENKINS-13024 Error in log indicating a missing descriptor
- JENKINS-9383 security - restrict access to internal objects
Can use now additional classpath for groovy postbuild scripts to have them in a central location. Scriptler Plugin?
Version 1.5 (November 5, 2011)
- Remove a html tag from the config page which causes an error on IE 7 (JENKINS-10079)