当我从上游作业触发时,不能使用Jenkins下游作业当前参数

时间:2016-10-25 11:02:07

标签: jenkins groovy jenkins-plugins

我有一个使用uno-choice dynamic choice parameter参数化的作业触发器(上游作业),以触发多个作业(下游作业)。

触发作业参数:

enter image description here

并且我使用此脚本使用构建后操作 - >触发所选作业 groovy post build

// param list of jobs to execute coming from upastream Job
def upstreamParam = "JOB_LIST_TRIGGER"
def upstreamParamFlag = "NEXT_RELEASE_TYPE"
def resolver = manager.build.buildVariableResolver
def JOBS_TO_EXECUTE = resolver.resolve(upstreamParam)
def FLAG = resolver.resolve(upstreamParamFlag )

def viewName = "test"
def jobsName = [] 

//only the NEXT RELEASE TYPE
def params = new hudson.model.StringParameterValue('NEXT_RELEASE_TYPE_BIS', FLAG)

// if no job selected in the parameter, will trigger all jobs in the view "test", otherwise  will execute only selected jobs
if (JOBS_TO_EXECUTE == null || JOBS_TO_EXECUTE == ''){

    // retrieve jobs names from jenkins view
    hudson.model.Hudson.instance.getView(viewName).items.each() {
           jobsName.push(it.getDisplayName())
    }

    // launch plugins jobs
        jobsName.each(){
          job = manager.hudson.getItem(it)
          cause = new hudson.model.Cause.UpstreamCause(manager.build)
          def paramsAction = new hudson.model.ParametersAction(params)
          causeAction = new hudson.model.CauseAction(cause)
          manager.hudson.queue.schedule(job, 0, causeAction, paramsAction)
       }
}else{

        // create a list of selected jobs in the JOB_LIST_TRIGGER param
    hudson.model.Hudson.instance.getView(viewName).items.each() {
           if (JOBS_TO_EXECUTE.contains(it.getDisplayName())){
              jobsName.push(it.getDisplayName())
           }
    }

        // launch only job selected in the JOB_LIST_TRIGGER param
        jobsName.each(){
            job = manager.hudson.getItem(it)
            cause = new hudson.model.Cause.UpstreamCause(manager.build)
            def paramsAction = new hudson.model.ParametersAction(params)
            causeAction = new hudson.model.CauseAction(cause)
            manager.hudson.queue.schedule(job, 0, causeAction, paramsAction)
         }
}

在此代码中我只触发 NEXT_RELEASE_PARAMETER 到下游作业。

job1..job4,其中包含以下详细信息,以显示当前的工作详情。

echo "------------------------------------------------"
echo "------------------------------------------------"
# the current param
echo $RELEASE_VERSION
echo "------------------------------------------------"
echo "------------------------------------------------"
# the current param
echo $NEXT_RELEASE_TYPE
echo "------------------------------------------------"
echo "------------------------------------------------"
# the upstream param
echo $NEXT_RELEASE_TYPE_BIS
echo "------------------------------------------------"
echo "------------------------------------------------"
# the current param
echo $NEXT_RELEASE
echo "------------------------------------------------"
echo "------------------------------------------------"

输出是:

+ echo ------------------------------------------------
------------------------------------------------
+ echo

+ echo ------------------------------------------------
------------------------------------------------
+ echo ------------------------------------------------
------------------------------------------------
+ echo

+ echo ------------------------------------------------
------------------------------------------------
+ echo ------------------------------------------------
------------------------------------------------
+ echo Major
Major
+ echo ------------------------------------------------
------------------------------------------------
+ echo ------------------------------------------------
------------------------------------------------
+ echo

+ echo ------------------------------------------------
------------------------------------------------
+ echo ------------------------------------------------
------------------------------------------------

结果只打印上游参数但不打印当前参数,所以有没有办法在作业触发器触发下游(job1..job4)当前参数后

0 个答案:

没有答案
相关问题