|
| 1 | +#!/bin/groovy |
| 2 | + |
| 3 | +library 'kibana-pipeline-library' |
| 4 | +kibanaLibrary.load() |
| 5 | + |
| 6 | +def CI_GROUP_PARAM = params.CI_GROUP |
| 7 | + |
| 8 | +// Looks like 'oss:ciGroup:1', 'oss:firefoxSmoke', or 'all:serverMocha' |
| 9 | +def JOB_PARTS = CI_GROUP_PARAM.split(':') |
| 10 | +def IS_XPACK = JOB_PARTS[0] == 'xpack' |
| 11 | +def JOB = JOB_PARTS[1] |
| 12 | +def NEED_BUILD = JOB != 'serverMocha' |
| 13 | +def CI_GROUP = JOB_PARTS.size() > 2 ? JOB_PARTS[2] : '' |
| 14 | +def EXECUTIONS = params.NUMBER_EXECUTIONS.toInteger() |
| 15 | +def AGENT_COUNT = getAgentCount(EXECUTIONS) |
| 16 | + |
| 17 | +def worker = getWorkerFromParams(IS_XPACK, JOB, CI_GROUP) |
| 18 | + |
| 19 | +def workerFailures = [] |
| 20 | + |
| 21 | +currentBuild.displayName += trunc(" ${params.GITHUB_OWNER}:${params.branch_specifier}", 24) |
| 22 | +currentBuild.description = "${params.CI_GROUP}<br />Agents: ${AGENT_COUNT}<br />Executions: ${params.NUMBER_EXECUTIONS}" |
| 23 | + |
| 24 | +kibanaPipeline(timeoutMinutes: 180) { |
| 25 | + def agents = [:] |
| 26 | + for(def agentNumber = 1; agentNumber <= AGENT_COUNT; agentNumber++) { |
| 27 | + def agentNumberInside = agentNumber |
| 28 | + def agentExecutions = floor(EXECUTIONS/AGENT_COUNT) + (agentNumber <= EXECUTIONS%AGENT_COUNT ? 1 : 0) |
| 29 | + agents["agent-${agentNumber}"] = { |
| 30 | + catchErrors { |
| 31 | + print "Agent ${agentNumberInside} - ${agentExecutions} executions" |
| 32 | + |
| 33 | + workers.functional('flaky-test-runner', { |
| 34 | + if (NEED_BUILD) { |
| 35 | + if (!IS_XPACK) { |
| 36 | + kibanaPipeline.buildOss() |
| 37 | + if (CI_GROUP == '1') { |
| 38 | + runbld("./test/scripts/jenkins_build_kbn_sample_panel_action.sh", "Build kbn tp sample panel action for ciGroup1") |
| 39 | + } |
| 40 | + } else { |
| 41 | + kibanaPipeline.buildXpack() |
| 42 | + } |
| 43 | + } |
| 44 | + }, getWorkerMap(agentNumberInside, agentExecutions, worker, workerFailures))() |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + parallel(agents) |
| 50 | + |
| 51 | + currentBuild.description += ", Failures: ${workerFailures.size()}" |
| 52 | + |
| 53 | + if (workerFailures.size() > 0) { |
| 54 | + print "There were ${workerFailures.size()} test suite failures." |
| 55 | + print "The executions that failed were:" |
| 56 | + print workerFailures.join("\n") |
| 57 | + print "Please check 'Test Result' and 'Pipeline Steps' pages for more info" |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +def getWorkerFromParams(isXpack, job, ciGroup) { |
| 62 | + if (!isXpack) { |
| 63 | + if (job == 'serverMocha') { |
| 64 | + return kibanaPipeline.functionalTestProcess('serverMocha', { |
| 65 | + kibanaPipeline.bash( |
| 66 | + """ |
| 67 | + source src/dev/ci_setup/setup_env.sh |
| 68 | + node scripts/mocha |
| 69 | + """, |
| 70 | + "run `node scripts/mocha`" |
| 71 | + ) |
| 72 | + }) |
| 73 | + } else if (job == 'accessibility') { |
| 74 | + return kibanaPipeline.functionalTestProcess('kibana-accessibility', './test/scripts/jenkins_accessibility.sh') |
| 75 | + } else if (job == 'firefoxSmoke') { |
| 76 | + return kibanaPipeline.functionalTestProcess('firefoxSmoke', './test/scripts/jenkins_firefox_smoke.sh') |
| 77 | + } else if(job == 'visualRegression') { |
| 78 | + return kibanaPipeline.functionalTestProcess('visualRegression', './test/scripts/jenkins_visual_regression.sh') |
| 79 | + } else { |
| 80 | + return kibanaPipeline.ossCiGroupProcess(ciGroup) |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + if (job == 'accessibility') { |
| 85 | + return kibanaPipeline.functionalTestProcess('xpack-accessibility', './test/scripts/jenkins_xpack_accessibility.sh') |
| 86 | + } else if (job == 'firefoxSmoke') { |
| 87 | + return kibanaPipeline.functionalTestProcess('xpack-firefoxSmoke', './test/scripts/jenkins_xpack_firefox_smoke.sh') |
| 88 | + } else if(job == 'visualRegression') { |
| 89 | + return kibanaPipeline.functionalTestProcess('xpack-visualRegression', './test/scripts/jenkins_xpack_visual_regression.sh') |
| 90 | + } else { |
| 91 | + return kibanaPipeline.xpackCiGroupProcess(ciGroup) |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +def getWorkerMap(agentNumber, numberOfExecutions, worker, workerFailures, maxWorkerProcesses = 12) { |
| 96 | + def workerMap = [:] |
| 97 | + def numberOfWorkers = Math.min(numberOfExecutions, maxWorkerProcesses) |
| 98 | + |
| 99 | + for(def i = 1; i <= numberOfWorkers; i++) { |
| 100 | + def workerExecutions = floor(numberOfExecutions/numberOfWorkers + (i <= numberOfExecutions%numberOfWorkers ? 1 : 0)) |
| 101 | + |
| 102 | + workerMap["agent-${agentNumber}-worker-${i}"] = { workerNumber -> |
| 103 | + for(def j = 0; j < workerExecutions; j++) { |
| 104 | + print "Execute agent-${agentNumber} worker-${workerNumber}: ${j}" |
| 105 | + withEnv([ |
| 106 | + "REMOVE_KIBANA_INSTALL_DIR=1", |
| 107 | + ]) { |
| 108 | + catchErrors { |
| 109 | + try { |
| 110 | + worker(workerNumber) |
| 111 | + } catch (ex) { |
| 112 | + workerFailures << "agent-${agentNumber} worker-${workerNumber}-${j}" |
| 113 | + throw ex |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + return workerMap |
| 122 | +} |
| 123 | + |
| 124 | +def getAgentCount(executions) { |
| 125 | + // Increase agent count every 24 worker processess, up to 3 agents maximum |
| 126 | + return Math.min(3, 1 + floor(executions/24)) |
| 127 | +} |
| 128 | + |
| 129 | +def trunc(str, length) { |
| 130 | + if (str.size() >= length) { |
| 131 | + return str.take(length) + "..." |
| 132 | + } |
| 133 | + |
| 134 | + return str; |
| 135 | +} |
| 136 | + |
| 137 | +// All of the real rounding/truncating methods are sandboxed |
| 138 | +def floor(num) { |
| 139 | + return num |
| 140 | + .toString() |
| 141 | + .split('\\.')[0] |
| 142 | + .toInteger() |
| 143 | +} |
0 commit comments