Execute a global configured groovy script after each build of each job managed by the Jenkins.
This is typical for cases when you need to do something based on a shared set of parameters, such as triggering downstream jobs managed by the same Jenkins or remote ones based on the parameters been passed to the parameterized jobs.
Notice: jython script support removed since 1.1.0
Plugin Information |
---|
View Global Post Script on the plugin site for more information. |
The current version of this plugin may not be safe to use. Please review the following warnings before use:
Global Configure
Default: the script will be executed when the build result is better or equal to UNSTABLE
Variables that could be used in the script file
Jenkins Built-in Variables
Variable | Description | Sample Data |
---|---|---|
BUILD_ID | Build timestamp as ID | 2014-06-26_07-16-51 |
BUILD_NUMBER | Build No# | 16 |
BUILD_RESULT | Build result | SUCCESS / UNSTABLE / FAILURE ... |
BUILD_TAG | Job Name + Build No# | jenkins-test-job-16 |
BUILD_URL | The URL of this build | |
JENKINS_HOME | The path of the root folder of Jenkins | ~/workspace-idea/global-post-script-plugin/./work |
JENKINS_URL | The root URL of Jenkins | |
JOB_NAME | Name of the job | test-job |
JOB_URL | URL of the job | |
MAVEN_CMD_LINE_ARGS | Maven command args | clean install |
NODE_LABELS | Lables of the nodes where the build could be executed | master |
NODE_NAME | Name of the node where the build executed | master |
SVN_REVISION | SVN revision | 185214 |
SVN_URL | SVN URL |
|
WORKSPACE | The path of the workspace | ~/workspace-idea/global-post-script-plugin/work/workspace/LOGANALYZE |
GIT_BRANCH | Git branch | origin/master |
GIT_COMMIT | Git commit ID | ddaf9c4576e375b42b6bc7c73daa12cb28a92031 |
GIT_URL | Git repo URL | https://github.com/jenkinsci/global-post-script-plugin.git |
Extra variables
Parameters of parameterized build
or parameters been passed in by -Dparameter_name=parameter_value
are also available
the manager
object
An extra object is available as groovy variables: manager
, provided 4 methods:
Method | Description |
---|---|
| Check if a variable is defined and usable in the script |
| Check if a variable is defined and usable in the script, and with a non-blank value |
| Add a badge to the build |
| Add a text label to the build |
| Trigger a job managed by the same Jenkins |
| Trigger a job by URL |
3rd-party libraries for groovy script
If your groovy script have dependencies that not shipped with Jenkins, you can put them into $JENKINS_HOME/global-post-script/lib
.
Supported Scripts
Groovy
out.println("dropdeploy to: $dropdeploy_targets")
out.println("dropdeploy to: " + dropdeploy_targets)
if (manager.isVar("variable_name")) { ... }
job = hudson.model.Hudson.instance.getItem("demo2") build = job.getLastBuild() println build def action = build.getAction(hudson.plugins.claim.ClaimBuildAction.class) print action.getReason()
def triggers = [ wwwsqs8: { def params = [ PARENT_BUILD_NUMBER: '$BUILD_NUMBER', PARENT_JOB_NAME: '$JOB_NAME', any_param_name: '$deploy_targets' ] manager.triggerJob("WWW_JBEHAVE_TEST", params) manager.triggerJob("WWW_MOBILE_API_TEST") manager.triggerRemoteJob("http://localhost/job/Dev_Launch_WWW_SQS_REGRESSION/build?token=88e4b5fd1d28949710a9c4924775ce40&delay=1800sec") }, wwwsqm8: { manager.triggerRemoteJob("http://localhost/job/Dev_Launch_WWW_SQM_REGRESSION/build?token=88e4b5fd1d28949710a9c4924775ce40&delay=1800sec") }, bsdsqs8: { manager.triggerJob("BSD_JBEHAVE_TEST") manager.triggerJob("BSD_MOBILE_API_TEST") manager.triggerRemoteJob("http://localhost/job/Dev_Launch_BSD_SQS_REGRESSION/build?token=88e4b5fd1d28949710a9c4924775ce40&delay=1800sec") }, bsdsqm8: { manager.triggerRemoteJob("http://localhost/job/Dev_Launch_BSD_SQM_REGRESSION/build?token=88e4b5fd1d28949710a9c4924775ce40&delay=1800sec") }, gmlsqs8: { manager.triggerJob("GMIL_JBEHAVE_TEST") manager.triggerRemoteJob("http://localhost/job/Dev_Launch_GMIL_SQS_REGRESSION/build?token=88e4b5fd1d28949710a9c4924775ce40&delay=1800sec") }, gmlsqm8: { manager.triggerRemoteJob("http://localhost/job/Dev_Launch_GMIL_SQM_REGRESSION/build?token=88e4b5fd1d28949710a9c4924775ce40&delay=1800sec") }, basepom: { manager.triggerJob("basepom") } ] if (manager.isVar("deploy") && manager.isNotBlankVar("deploy_targets") && "true" == deploy) { dropped = false deploy_targets.split(',').each { trigger = triggers[it] if (trigger) { trigger() dropped = true } } if (dropped) { manager.addBadge("server.png", "[SQ: " + deploy_targets + "]") } }
bat/sh
NO variables will passed into the script
Open Issues
Changes
1.1.4
- Added support for `pipeline`JENKINS-44647
1.1.3
- Fixed JENKINS-37796 Loading jars in
global-post-script/lib
(if exist) as classpath entries when running groovy script.
1.1.2
- Not the cache the parsed GroovyShell
1.1.1.1
- *Do NOT use this version*
- Fixed JENKINS-34056
1.1.1
- *Do NOT use this version*
- Parsing and caching the groovy script, to make a smaller footprint. JENKINS-33358
1.1.0
- Added `aborted` condition, to allow triggering the script even the build is aborted.
- Removed support for jython scripts. (jython dependency is too big, and Groovy is much better supported by Jenkins.)
1.0.12
- Fixed issue about script been executed for each sub-module of Maven multi-module projects.
1.0.11
- Fixed issue about groovy script works in
script console
but fails asglobal post script
1.0.10
- Allow to run also for failed builds (Global configure).
- Added BUILD_RESULT to script.
1.0.9
- Supports parameters when triggering local jobs (parameterized downstream jobs)
Attachments:
Screenshot from 2015-06-23 20:46:28.png (image/png)
global-config.png (image/png)
global-config.png (image/png)
global-config.png (image/png)