You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins被调用项目构建信息编辑问题及Groovy脚本报错求助

问题解决:Jenkins被调用项目构建信息设置失败及manager属性报错

一、修正调用流水线的语法错误

原调用代码存在语法错误(多余的]),且参数传递格式不正确,正确写法如下:

pipeline {
    agent any
    stages {
        stage('调用目标项目') {                                   
            steps{                       
                build job: 'Proyect called', 
                      parameters: [string(name: "DESCRIPTION", value: "ProjectCalled full launched")]
            }                   
        }   
    }
}

二、解决manager属性不存在的报错

manager是旧版Groovy Postbuild插件专属对象,在系统Groovy脚本或流水线环境中无法直接使用,需通过Jenkins原生API获取当前构建对象:

方案1:自由风格项目(系统Groovy脚本)

修改被调用项目的系统Groovy脚本为:

import hudson.model.*

// 获取当前构建实例
def build = Thread.currentThread().executable
// 获取传递的参数集合
def paramsAction = build.getAction(ParametersAction.class)

if (paramsAction != null) {
    def descriptionParam = paramsAction.getParameter("DESCRIPTION")
    if (descriptionParam != null) {
        def description = descriptionParam.getValue()
        println "Setting build description to: ${description}"
        // 设置构建描述(会显示在Edit Build Information区域)
        build.setDescription(description)
        // 如需添加构建摘要信息,可启用下面的代码
        // build.createSummary("info.gif").appendText(description, false)
    }
}

方案2:流水线项目(直接集成到流水线)

如果被调用项目是流水线类型,无需额外Groovy脚本,直接在流水线中添加设置逻辑:

pipeline {
    agent any
    // 定义接收的参数
    parameters {
        string(name: 'DESCRIPTION', defaultValue: '', description: '构建描述信息')
    }
    stages {
        // 你的业务阶段代码
    }
    post {
        always {
            // 将参数值设置为构建描述
            currentBuild.description = params.DESCRIPTION
        }
    }
}

三、前置配置要求

  • 被调用项目必须是参数化项目:自由风格项目需在「参数化构建过程」中添加名为DESCRIPTION的字符串参数;流水线项目通过上述parameters块定义。
  • 若使用系统Groovy脚本,需确保Jenkins已审批该脚本涉及的API调用(路径:Manage Jenkins → In-process Script Approval)。

内容的提问来源于stack exchange,提问作者sergio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 00:35:19