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

Jenkins input步骤点击Abort按钮后接收值为null问题咨询

问题成因

Jenkins的input步骤内置设计逻辑为:当用户点击交互弹窗的Abort按钮终止操作时,步骤不会直接抛出异常中断流水线,而是默认返回null值作为执行结果。该表现与你使用的参数类型(下拉选择、文本框、布尔值等)无关,属于框架层面的固定行为。

处理方案
  • 方案1:新增非空校验,空值时主动终止流水线
    对USER_INPUT变量做合法性校验,检测到null值时调用error方法主动终止流水线,避免后续逻辑执行异常,参考代码如下:
script {
        // Define Variable
         def USER_INPUT = input(
                message: 'User input required - Some Yes or No question?',
                parameters: [
                        [$class: 'ChoiceParameterDefinition',
                         choices: ['no','yes'],
                         name: 'input',
                         description: 'Menu - select box option']
                ])

        // 新增空值校验逻辑
        if (USER_INPUT == null) {
            error "用户已终止交互步骤,流水线中止运行"
        }

        echo "The answer is: ${USER_INPUT}"
    }
  • 方案2:通过try-catch包裹逻辑,自定义Abort后操作
    如果你需要在用户点击Abort后执行清理、日志上报等自定义逻辑,可以将input步骤放入try-catch块中处理:
script {
        def USER_INPUT
        try {
            USER_INPUT = input(
                    message: 'User input required - Some Yes or No question?',
                    parameters: [
                            [$class: 'ChoiceParameterDefinition',
                             choices: ['no','yes'],
                             name: 'input',
                             description: 'Menu - select box option']
                    ])
        } catch (Exception e) {
            // 此处可添加清理、日志记录等自定义逻辑
            echo "检测到用户终止交互,执行收尾操作"
            error "流水线已被用户手动中止"
        }

        echo "The answer is: ${USER_INPUT}"
    }
  • 方案3:可选优化,添加submitterParameter参数明确返回结构
    若业务需要区分提交用户和提交参数,可添加该参数明确返回值结构,降低空值处理的歧义,该配置不会改变Abort返回null的底层逻辑,仅用于业务逻辑分层。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 10:06:02