如何在jenkins中多次运行相同的脚本化管道?

ct2axkht  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(209)

我在互联网上寻找一种方法来多次运行相同的管道,但没有找到答案。基本上,管道有5个阶段,我希望这个管道运行5次,管道的每次迭代将以相同的顺序执行代码中的阶段。

node{

def build_ok = true

    try{
    stage('#1 SoftSync 4.5.1 CPU Usage Test') {
          build job: 'SoftSync_4.5.1_CPU_Usage_Test', parameters: [string(name: 'LOG_LEVEL', value: 'debug'), string(name: 'FILE_PATH', value: 'TLV_SoftSync/Management_Bundle/SoftSync_CPU_Usage_Test.robot')]
    }
    } catch(e) {
        build_ok = false
        echo e.toString()  
    }

    try{
    stage ('#2 SoftSync 4.5.1 Improvments to system time management Test '){
        build job: 'SoftSync_4.5.1_Improvments_To_System_TimeManagement_Test', parameters: [string(name: 'LOG_LEVEL', value: 'debug'), string(name: 'FILE_PATH', value: 'TLV_SoftSync/Management_Bundle/SoftSync_Improvments_to_system_time_management.robot')]
    }
    }catch(e) {
        build_ok = false
        echo e.toString() 
    }

    try {
    stage ('#3 SoftSync 4.5.1 Telematics and statistics Test'){
       build job: 'SoftSync_4.5.1_Telematics_and_statistics_Test', parameters: [string(name: 'LOG_LEVEL', value: 'debug'), string(name: 'FILE_PATH', value: 'TLV_SoftSync/Management_Bundle/SoftSync_Telementry_and_Statistics.robot')]
    }
    }catch(e) {
        build_ok = false
        echo e.toString() 
    }

    //try{
      //stage ('#4 SoftSync 4.5.1 PTP Profiles Slave Lock Test'){
        build job: 'SoftSync_4.5.1_PTP_Profiles_SlaveLock_Test', parameters: [string(name: 'LOG_LEVEL', value: 'debug'), string(name: 'FILE_PATH', value: 'TLV_SoftSync/PTP_Bundle/SoftSync_PTP_Lock_validation.robot')]
    //} 
    //}catch(e) {
    //    build_ok = false
    //    echo e.toString() 
    //}

    try{
      stage ('#5 SoftSync 4.5.1 Alarms Test'){
       build job: 'SoftSync_4.5.1_Alarms_Test', parameters: [string(name: 'LOG_LEVEL', value: 'debug'), string(name: 'FILE_PATH', value: 'TLV_SoftSync/Management_Bundle/SoftSync_Alarms_Test.robot')]
    }
    }catch(e) {
        build_ok = false
        echo e.toString() 
    }

if(build_ok) {
    currentBuild.result = "SUCCESS"
} else {
    currentBuild.result = "FAILURE"
}

post{
    always{
        junit allowEmptyResults: true, testResults: '/var/lib/jenkins/output/*.xml'
    }
}
}

我见过一些使用数组和。每个函数,但都是并行使用,这对我的情况没有帮助。
有什么主意吗?

rhfm7lfc

rhfm7lfc1#

你可以用一个循环来 Package 你的阶段。

node {
    def itrList = ["Run1", "Run2", "Run3"]
    itrList.each { val ->

        def build_ok = true
        try {
            stage("#1 SoftSync 4.5.1 CPU Usage Test with $val") {
                echo "111111"
            }
        } catch (e) {
            build_ok = false
            echo e.toString()
        }

        try {
            stage("#2 SoftSync 4.5.1 Improvments to system time management Test  with $val") {
                echo "22222222222"
            }
        } catch (e) {
            build_ok = false
            echo e.toString()
        }

        if (build_ok) {
            currentBuild.result = "SUCCESS"
        } else {
            currentBuild.result = "FAILURE"
        }
    }
}

相关问题