【问题标题】:Dynamic Parameters of one jenkins job is to be picked up automatically by other jenkins job一个詹金斯作业的动态参数将被其他詹金斯作业自动拾取
【发布时间】:2015-12-15 12:46:21
【问题描述】:

我有一个 jenkins 作业 A 可以在构建作业时从参数中选择任何选项,每当我尝试构建作业 B 时,作业 B 应该自动选择我在作业 A 上选择的相同参数值。作业 B 不应该是作业 A 的下游作业。

我的解决方法:我尝试将我在作业 A 上选择的参数复制到一个文件中。

在作业 B 中,我无法在 jenkins 中找到选项,以便从参数部分的文件中选择要提取的变量值。

我们将不胜感激任何建议和不同的方法。

【问题讨论】:

    标签: jenkins jenkins-plugins jenkins-workflow


    【解决方案1】:

    您可以使用 System Groovy 脚本执行此操作。您找到最新的作业 A 构建,并将参数值复制到作业 B。

    import hudson.model.*
    def hif = Hudson.instance
    
      //Get build variables for this build
    def buildMap = build.getBuildVariables() 
    
    //get most recent build of project A
    def a = hif.getItems(hudson.model.Project).find {it.displayName.toUpperCase()=='PROJECT A'}.getBuilds().first()
    
    //Add parameter to the build variables for this build
    buildMap['MYPARAM']=a.buildVariableResolver.resolve('MYPARAM')
    println(buildMap['MYPARAM'])
    
    
    //Assign the new parameters back to job B
    setBuildParameters(buildMap)
    
    def setBuildParameters(map) {
        def npl = new ArrayList<StringParameterValue>()
        for (e in map) {
            npl.add(new StringParameterValue(e.key.toString(), e.value.toString()))
        }
        def newPa = null
        def oldPa = build.getAction(ParametersAction.class)
        if (oldPa != null) {
            build.actions.remove(oldPa)
            newPa = oldPa.createUpdated(npl)
        } else {
            newPa = new ParametersAction(npl)
        }
        build.actions.add(newPa)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多