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

如何修改Jenkins Docker Pipeline插件中docker run的默认参数?

解决Jenkins Docker代理默认添加-t参数导致poetry shell报错的问题

核心解决方案

在Jenkinsfile的Docker Agent配置中添加tty false,即可禁用Jenkins默认自动添加的-t参数:

修改后的Jenkinsfile示例:

pipeline {
    agent { docker {
        image 'matiasch/python3.11-poetry1.7'
        args '-u root --privileged'
        tty false  // 关闭默认的伪终端分配,移除-t参数
    } }
    stages {
        stage('Install Dependencies') {
            steps {
                timeout(time: 5, unit: 'MINUTES') {
                    sh 'poetry install'
                    // 注意:Jenkins流水线是非交互式环境,poetry shell无实际作用
                    // 后续需要在虚拟环境执行的命令,直接用poetry run前缀即可,比如:
                    // sh 'poetry run pytest'
                }
            }
        }
    }
}

补充说明

  1. Jenkins的Docker Agent默认会自动添加-t参数来分配伪终端,而poetry shell在非交互式环境下不需要这个配置,关闭后就能解决(25, 'Not a tty')的报错。
  2. 在Jenkins流水线这种非交互式场景中,不需要使用poetry shell——它是用于交互式进入虚拟环境的工具,流水线里直接用poetry run [命令]就能在虚拟环境中执行指定命令,完全替代进入shell的操作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 21:25:55