如何在独立的 Pod 中运行声明性詹金斯管道的并行阶段

mar*_*uru 5 parallel-testing jenkins jenkins-pipeline jenkins-declarative-pipeline jenkins-kubernetes

我正在尝试在声明性 jenkins 管道上的不同kubernetes pod 上并行运行一些端到端测试,但 jenkins 似乎尝试在相同的kubernetes pod 上运行并行阶段。这会导致数据库死锁,因为两个进程都尝试插入/截断/更新/查询相同的表。有没有办法可以为每个并行阶段启动不同的 Pod?

kubernetes 插件配置:

  agent {
  kubernetes {
    label 'my-label'
    defaultContainer 'jnlp'
    yaml """
apiVersion: v1
kind: Pod
metadata:
  name: dind
spec:
  containers:
    - name: < default container >
      image: < image >
      securityContext:
          privileged: true
          fsGroup: 1000
      command:
      - cat
      tty: true
      volumeMounts:
        - name: jenkins-bundle-gems
          mountPath: /usr/local/bundle


    - name: <tests-container-name>
      image: < image > 
      securityContext:
          privileged: true
          fsGroup: 1000
      volumeMounts:
        - name: jenkins-bundle-gems
          mountPath: /usr/local/bundle
      command:
      - cat
      tty: true
"""
 }
   }
Run Code Online (Sandbox Code Playgroud)

并行阶段:

      stage('Test'){
        parallel {
          stage("Branch 1") {
              steps {
                container('<tests-container-name>') {
                  sh "jenkins/scripts/initdb.sh"
                  sh 'bundle exec rspec --exclude-pattern "spec/features/*_spec.rb" spec'
                }
              }
            }
            stage("Branch 2") {
              steps {
                container('<tests-container-name>') {
                  sh "jenkins/scripts/initdb.sh"
                  sh "bundle exec rspec `jenkins/scripts/split_features.sh 0`"
                }
              }
            }
        }
      }
Run Code Online (Sandbox Code Playgroud)

期望:我希望詹金斯为每个并行阶段旋转两个不同的吊舱。这将使我能够为每个测试使用不同的数据库。

实际结果: Jenkins 在同一个 Pod 上同时运行两个阶段。