How to run same job with different parameters in parallel using parallel[:] step

(hagay) #1

I have a pipeline script that needs to trigger a “TEST” job. The main parameter (string) is SETUP_DESCRIPTION which I phrase from a json file im creating. Each server can have different amount of outputs depends on server resources (some have 2 setups and some 3).

Code looks like this:

  1. When I run it like code above build_sanity function called once and execute (instead of 3 times as expected).

  2. When I take build_sanity function content and run it inside the ech loop in the tests stage it runs 3 times as expected but not choosing different parameters as expected.

#!/usr/bin/env groovy
import hudson.model.Result
import hudson.model.Run
import groovy.json.JsonSlurperClassic
import jenkins.model.CauseOfInterruption.UserInterruption
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException

def projectProperties = [
logRotator(artifactDaysToKeepStr: ‘’, artifactNumToKeepStr: ‘’, daysToKeepStr: ‘14’, numToKeepStr: ‘’)
string(defaultValue: ‘’, description: ‘’, name: ‘SERVER_NAME’),
string(defaultValue: ‘Ubuntu_17.10_x86_64_kvm’, description: ‘’, name: ‘KVM_TEMPLATE’),
string(defaultValue: ‘[email protected]’’, description: ‘mailing list’, name: ‘SW_MAIL’),
choice(choices: [‘no’, ‘eth’, ‘ib’], description: ‘’, name: ‘SIMX_SERVER’),
choice(choices: [‘cib’, ‘cx3pro’, ‘cx4’, ‘cx4lx’, ‘cx5’, ‘cx6’], description: ‘’, name: ‘SIMX_BOARD’),
choice(choices: [‘os_install’, ‘provision’, ‘add_jks_slave’, ‘add_to_noga’, ‘tests’], description: ‘’, name: ‘RUN_STAGE’)
[$class: ‘RebuildSettings’, autoRebuild: false, rebuildDisabled: false],
[$class: ‘ThrottleJobProperty’,
categories: [],
limitOneJobWithMatchingParams: true,
maxConcurrentPerNode: 5,
maxConcurrentTotal: 5,
paramsToUseForLimit: ‘’,
throttleEnabled: true,
throttleOption: ‘project’

def build_sanity (SETUP_DESCRIPTION) {

                IMAGE = "linux/upstream_devel-x86_64"
                CLOUD_IP = "dev-l-vrt-storage"
                TAGS = "test_new_setup"

            if ("$SETUP_DESCRIPTION" != "b2b x86-64 cib cloud_test") {
                DATA_BASE = "b2b_eth_drivertest_mini_reg_db.json"
                LINK_LAYER =  "eth"
            else {
                DATA_BASE = "b2b_ib_drivertest_mini_reg_db.json"
                LINK_LAYER =  "ib"

        build job: 'SANITY_TESTS/new_cloud_setup_GENERAL_SANITY_CHECK2', propagate: false
        [string(name: 'SETUP_DESCRIPTION', value: "${SETUP_DESCRIPTION}"),
        string(name: 'DATA_BASE', value: "${DATA_BASE}"),
        string(name: 'LINK_LAYER', value: "${LINK_LAYER}"),
        string(name: 'IMAGE', value: "${IMAGE}"),
        string(name: 'CLOUD_IP', value: "${CLOUD_IP}"),
        string(name: 'TAGS', value: "${TAGS}")]

try {
ansiColor(‘xterm’) {
timestamps {

        stage('Test Setups') {
           if (params.RUN_STAGE == 'os_install' || params.RUN_STAGE == 'provision' || params.RUN_STAGE == 'add_jks_slave' || params.RUN_STAGE == 'add_to_noga' || params.RUN_STAGE == 'tests') {

             def stepsForParrallel = [:]
             def NOGA_DESCRIPTION_LIST = sh (
                script: "curl -X GET '${params.SERVER_NAME}&resource_type=Setup&group_name=Yaron&sub_group=Cloud'",
                returnStdout: true

            def JSON = new groovy.json.JsonSlurperClassic().parseText(NOGA_DESCRIPTION_LIST)
            def DESCRIPTION_LIST ={
                SETUP_NAME = "${it.NAME}"
                SETUP_DESCRIPTION = "${it.DESCRIPTION}"
                println "${it.DESCRIPTION}" // PRINT ALL DECRIPTIONS INSIDE DATA

                stepsForParrallel["${it.NAME}"] = {

          parallel stepsForParrallel

}catch (exc) {
def recipient = “${SW_MAIL}”
def subject = “${env.JOB_NAME} (${env.BUILD_NUMBER}) Failed”
def body = “”"
It appears that build ${env.BUILD_NUMBER} is failing, please check HW or network stability:
mail subject: subject,
to: recipient,
replyTo: recipient,
from: ‘[email protected]’,
body: body

throw exc