容器步骤中的 Jenkins K8s 插件 WebSocket 超时

Jenkins K8s plugin WebSocket Timeout in container step

我已经创建了一个K3d集群。我已经在内部部署了一个 jenkins 2.319.1 控制器,以及 kubernetes 插件 1.31.1(和 git、管道等) 这个想法是 运行 同一集群中的控制器和代理。为此,我配置了一个云,如下图所示: [云配置][1] [1]: https://i.stack.imgur.com/u91Fr.png

(我已经用不同的组合尝试了几次代理连接到控制器。最后我一直使用 JNLP - 没有 WebSOCKET - 尽管无论如何,我将要描述的超时对于两者)

配置云并能够生成代理后,经过多次尝试,我终于发现该作业在容器步骤内执行时挂起(并因超时而死)。默认“jnlp”容器内的操作是可以的,但是当你做一些微不足道的事情时:sh 'ls -l' 在另一个容器内,作业在 30 秒后终止,并显示以下日志:

    >    .
.
.
.
   readOnly: false
      nodeSelector:
        kubernetes.io/os: "linux"
      restartPolicy: "Never"
      volumes:
      - emptyDir:
          medium: ""
        name: "workspace-volume"
    
    Running on prueba-6-tj9w5-r0qt9-kcst4 in /home/jenkins/agent/workspace/Prueba
    [Pipeline] {
    [Pipeline] stage
    [Pipeline] { (Get a Maven project)
    [Pipeline] sh
    + git config --global http.proxy http://10.11x.xx.xx:8080
    [Pipeline] sh
    + git config --global https.proxy http://10.11x.xx.xx:8080
    [Pipeline] git
    The recommended git tool is: NONE
    No credentials specified
    Cloning the remote Git repository
    Cloning repository https://github.com/jenkinsci/kubernetes-plugin.git
     > git init /home/jenkins/agent/workspace/Prueba # timeout=10
    Fetching upstream changes from https://github.com/jenkinsci/kubernetes-plugin.git
     > git --version # timeout=10
     > git --version # 'git version 2.30.2'
     > git fetch --tags --force --progress -- https://github.com/jenkinsci/kubernetes-plugin.git +refs/heads/*:refs/remotes/origin/* # timeout=10
    Avoid second fetch
    Checking out Revision a61114b275425489761f095e8a89b19cf2ab5c8e (refs/remotes/origin/master)
     > git config remote.origin.url https://github.com/jenkinsci/kubernetes-plugin.git # timeout=10
     > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
     > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
     > git config core.sparsecheckout # timeout=10
     > git checkout -f a61114b275425489761f095e8a89b19cf2ab5c8e # timeout=10
     > git branch -a -v --no-abbrev # timeout=10
     > git checkout -b master a61114b275425489761f095e8a89b19cf2ab5c8e # timeout=10
    Commit message: "[maven-release-plugin] prepare for next development iteration"
    First time build. Skipping changelog.
    [Pipeline] container
    [Pipeline] {
    [Pipeline] stage
    [Pipeline] { (Build a Maven project)
    [Pipeline] sh
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] }
    [Pipeline] // container
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] }
    [Pipeline] // podTemplate
    [Pipeline] End of Pipeline
    java.io.IOException: Timed out waiting for websocket connection. You should increase the value of system property org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator.websocketConnectionTimeout currently set at 60 seconds
        at org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator.doLaunch(ContainerExecDecorator.java:457)
        at org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator.launch(ContainerExecDecorator.java:344)
        at hudson.Launcher$ProcStarter.start(Launcher.java:507)
.
.
.

我不知道 websocket 消息,因为在云配置中这显然是未选中的。正如我提到的,如果我检查 websocket(以及清除隧道),我会得到相同的结果。

我不知道这是否与 jenkins 运行ning 在 dockerized 集群中有关。我在 windows 的 wsl2 和 rhel 7.9.

中都安装了相同的集群 (k3d v4.4.7)

使用的示例管道(最后一个借用自):

> podTemplate(containers: [
    containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'),
    containerTemplate(name: 'golang', image: 'golang:1.8.0', ttyEnabled: true, command: 'cat')
  ]) {

    node(POD_LABEL) {
        env.http_proxy='http_proxy=http://10.11x.xx.xx:8080'
        env.https_proxy='http_proxy=http://10.11x.xx.xx:8080'
        stage('Get a Maven project') {
            sh 'git config --global http.proxy http://10.11x.xx.xx:8080'
            sh 'git config --global https.proxy http://10.11x.xx.xx:8080'
            git 'https://github.com/jenkinsci/kubernetes-plugin.git'
            container('maven') {
                stage('Build a Maven project') {
                    sh 'mvn -B clean install'
                }
            }
        }

        stage('Get a Golang project') {
            git url: 'https://github.com/hashicorp/terraform.git'
            container('golang') {
                stage('Build a Go project') {
                    sh """
                    mkdir -p /go/src/github.com/hashicorp
                    ln -s `pwd` /go/src/github.com/hashicorp/terraform
                    cd /go/src/github.com/hashicorp/terraform && make core-dev
                    """
                }
            }
        }
    }
}

此致

正如之前评论中提到的 post () 将 kubernetes 插件升级到 v1.31.2 解决了这个问题。已经修补和测试。

韩国