如何通过Groovy Script获取上游job的parameter

question description: 

有一个Job A,trigger Job B,在job A中我在predefined parameters 里面定义了如下几个参数jobName=$JOB_NAME
buildNumber=$BUILD_NUMBER
buildUrl=$BUILD_URL

现在,我要在job B中获取。Groovy脚本可以写成这样子:

import hudson.model.*

def jobName="";
def buildNumber="";
def buildUrl="";

def thr = Thread.currentThread()
def build = thr?.executable
def     parameters = build?.actions.find{ it instanceof ParametersAction }?.parameters
parameters.each {
    def name = "${it.name}";
    def value = "${it.value}"
    println "parameter---"+name
    println "value---"+value
    switch (name){
        case "jobType":
            jobType=value;
            break;
        case "jobName":
            jobName=value;
            break;
        case "buildNumber":
            buildNumber=value;
            break;
        case "buildUrl":
            buildUrl=value;
            break;
    }

}
println "jobType="+jobType
println "jobName="+jobName
println "buildNumber="+buildNumber
println "buildUrl="+buildUrl


你可能感兴趣的:(如何通过Groovy Script获取上游job的parameter)