jeudi 24 mai 2018

How to Run same set of jobs on multiple nodes using Jenkins Pipeline

I have a pipeline that is starting VMs and running some tests on them. For parameters, I use two strings: one to indicate the list of test cases or VM management operations and another for the list of node names. Currently, the pipeline executes first on one node and then on the next. I need them it to execute on all nodes simultaneously. I tried using parallel and it can't co-exist with the for loops. Here is my script:

nodes = params._RNX_OS.split('¤');
for (String VMnode : nodes) {

stage("Prepare environment"){
    build job: "TA_StartVM", parameters: [string(name: "_RNX_OS", value: VMnode), string (name:"_RNX_SNAPSHOT", value:"Configured")];
}

configs = params._RNX_STAGES.toString().split('¤');
for (String config : configs) {
    switch (config) {
        case "Restart":
            stage("Restart VM"){
            build job: 'TA_RestartVM', parameters: [string(name: "_RNX_OS", value: VMnode)];
            }
            break
        case ~/.*Start.*/:
                param = config.toString().split(':');
                snapshot = param[1];
            stage("Start VM"){
            build job: 'TA_StartVM', parameters: [string(name: "_RNX_OS", value: VMnode), string (name:"_RNX_SNAPSHOT", value: snapshot)];
            }
            break
         case "Shutdown":
            stage("Shut down VM"){
            build job: 'TA_ShutdownVM', parameters: [string(name: "_RNX_OS", value: VMnode)];
            }
            break
         case ~/.*Save.*/:
              param = config.toString().split(':');
                snapshot = param[1]
            stage("Save VM Snapshot"){
            build job: 'TA_SaveVMSnapshot', parameters: [string(name: "_RNX_OS", value: VMnode), string (name:"_RNX_SNAPSHOT", value: snapshot)];
            }
            break
        default:
        stage("Run " +config + " Test"){
            build job: 'TA_RunTest', parameters: [[$class: 'LabelParameterValue', name: 'node', label: VMnode], string(name: "_RNX_TESTCONF", value: config), string(name: "_RNX_OS", value: VMnode)], propagate: false;
        }
        break 
    }
}

stage("Test Results Table"){
        build job: 'TA_TestResultsTable',parameters: [[$class: 'LabelParameterValue', name: 'node', label: VMnode]], propagate: false;
}

stage("Publish Test Results"){
    build job: 'TA_CopyTestResults', propagate: false;
}
stage("Stop Slave"){
    build job: "TA_ShutdownVM", parameters: [string(name: "_RNX_OS", value: VMnode)];
}
}

Aucun commentaire:

Enregistrer un commentaire