Jenkins并行在内部包含多个阶段

v64noz0r  于 2023-08-03  发布在  Jenkins
关注(0)|答案(1)|浏览(86)
def run(service) {
    task = {
        def thing = null
        waitUntil {
            thing = latch.pollFirst();
            return thing != null;
        }
        try {
            stage("${service}") {
                withEnv(["service=${service}"]){
                    stages {
                        stage('1') {
                            script {
                                sh """
                                    sleep 6
                                """
                            }
                        }
                        stage('2') {
                            script {
                                sh """
                                    sleep 6
                                """
                            }
                        }
                    }
                }
            }
        }
        finally {
            latch.offer(thing)
        }        
    }
  return task
}

pipeline {
    agent {
        label "74"
    }

    options {
      timestamps()
    }

    stages {
        stage("Pipeline") {
            steps {
                script {
                    def task = [:]
                    MAX_CONCURRENT = 1
                    latch = new java.util.concurrent.LinkedBlockingDeque(MAX_CONCURRENT)
                    for(int i=0; i<MAX_CONCURRENT; i++)
                        latch.offer("$i")
                    // for (service in model_list.tokenize('\n')){
                    final foundFiles = sh(script: 'ls -1 post', returnStdout: true).split()
                    for (service in foundFiles){
                        task[service] = run(service)
                    }
                    
                    parallel task
                }
            }
        }
    }
}

字符串
在上面的代码中,我想根据文件夹中的文件数量创建尽可能多的文件夹,然后在一个单独的阶段中会有多个文件夹,但我得到了一个错误,java.lang.NoSuchMethodError:步骤中未找到此类DSL方法“stages”

def run(service) {
    task = {
        def thing = null
        waitUntil {
            thing = latch.pollFirst();
            return thing != null;
        }
        try {
            stage("${service}") {
                withEnv(["service=${service}"]){
                    script {
                        sh """
                            ls ${service}
                        """
                    }
                }
            }
        }
        finally {
            latch.offer(thing)
        }        
    }
  return task
}


我可以执行它,但对于每个Satge,只有一个Satge,现在我想在每个Satge中有多个Satge,但我不知道该怎么办

kadbb459

kadbb4591#

try {
    node('228') {
        stage("${service}") {
            withEnv(["service=${service}"]){
                stage('run') {
                    script {
                        sh """
                            sleep 6
                        """
                    }
                }
                stage('analysis') {
                    script {
                        catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
                            sh """
                                sleep 6
                            """
                        }
                    }
                }
            }
        }
    }
}

字符串
ok,我解决了,你可以的

相关问题