Skip to content
orctom edited this page Nov 6, 2014 · 3 revisions

global-post-script-plugin

Execute a global configured groovy/python script after each build of each job managed by the Jenkins

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_TAG Job Name + Build No# jenkins-test-job-16
BUILD_URL The URL of this build http://localhost:8080/job/test-job/16/
JENKINS_HOME The path of the root folder of Jenkins ~/workspace-idea/global-post-script-plugin/./work
JENKINS_URL The root URL of Jenkins http://localhost:8080/
JOB_NAME Name of the job test-job
JOB_URL URL of the job http://localhost:8080/job/test-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

Extra variables

Parameters of parameterized build or parameters been passed in by -Dparameter_name=parameter_value are also available

manager

An extra object is available as groovy variables: manager, provided 4 methods:

Method Description
addBadge(String icon, String text) Add a badge to the build
addShortText(String text) Add a text label to the build
triggerJob(String jobName) Trigger a job managed by the same Jenkins
triggerRemoteJob(String url) Trigger a job by URL

Supported Scripts

Groovy

Sample:

out.println("dropdeploy to: $dropdeploy_targets")

Sample:

out.println("dropdeploy to: " + dropdeploy_targets)

Sample:

if (binding.variables.containsKey("variable_name")) {
    ...
}

Sample:

def triggers = [
        wwwsqs8: {
            manager.triggerJob("WWW_JBEHAVE_TEST")
            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 (binding.variables.containsKey("deploy") && binding.variables.containsKey("deploy_targets") &&
        "true" == deploy && deploy_targets?.trim()) {
    manager.addBadge("computer.png", "[DEV: " + deploy_targets + "]")
}
if (binding.variables.containsKey("dropdeploy") && binding.variables.containsKey("dropdeploy_targets") &&
        "true" == dropdeploy && dropdeploy_targets?.trim()) {
    dropped = false
    dropdeploy_targets.split(',').each {
        trigger = triggers[it]
        if (trigger) {
            trigger()
            dropped = true
        }
    }
    if (dropped) {
        manager.addBadge("server.png", "[SQ: " + dropdeploy_targets + "]")
    }
}

Python (Jython)

Sample:

print 'dropdeploy to: ' + dropdeploy_targets + ", " +  manager.getCause()

Sample:

if 'variable_name' in locals():
    ...

Sample:

str = 'dropdeploy to: '
if 'dropdeploy_targets' in locals():
    str += dropdeploy_targets
if 'manager' in locals():
    str += ", " + manager.getCause()
print str

bat/sh

NO variables will passed into the script

Clone this wiki locally