diff --git a/jenkins_pipelines/environments/common/pipeline-build-validation.groovy b/jenkins_pipelines/environments/common/pipeline-build-validation.groovy index ae9d7952b..6bae2320d 100644 --- a/jenkins_pipelines/environments/common/pipeline-build-validation.groovy +++ b/jenkins_pipelines/environments/common/pipeline-build-validation.groovy @@ -22,6 +22,7 @@ def run(params) { // Declare lock resource use during node bootstrap mgrCreateBootstrapRepo = 'share resource to avoid running mgr create bootstrap repo in parallel' retailProxyConfigurationLock = 'lock proxy retail setup' + def muLockSlots = [].asSynchronized() // Variables to store none critical stage run status def monitoring_stage_result_fail = false def client_stage_result_fail = false @@ -587,13 +588,15 @@ def clientTestingStages(params) { if (params.confirm_before_continue) { input 'Press any key to start adding Maintenance Update repositories' } - echo 'Add custom channels and MU repositories' - res_mu_repos = runCucumberRakeTarget("cucumber:build_validation_add_maintenance_update_repositories_${nodeTag}", true, temporaryList) - echoHtmlReportPath("build_validation_add_maintenance_update_repositories_${nodeTag}") - echo "Custom channels and MU repositories status code: ${res_mu_repos}" - if (res_mu_repos != 0) { - required_custom_channel_status[node] = 'FAIL' - error("Add custom channels and MU repositories failed with status code: ${res_mu_repos}") + withThrottle(muLockSlots, 5) { + echo 'Add custom channels and MU repositories' + res_mu_repos = runCucumberRakeTarget("cucumber:build_validation_add_maintenance_update_repositories_${nodeTag}", true, temporaryList) + echoHtmlReportPath("build_validation_add_maintenance_update_repositories_${nodeTag}") + echo "Custom channels and MU repositories status code: ${res_mu_repos}" + if (res_mu_repos != 0) { + required_custom_channel_status[node] = 'FAIL' + error("Add custom channels and MU repositories failed with status code: ${res_mu_repos}") + } } } } @@ -611,13 +614,15 @@ def clientTestingStages(params) { if (params.confirm_before_continue) { input 'Press any key to start adding common channels' } - echo 'Add non MU Repositories' - res_non_MU_repositories = runCucumberRakeTarget("cucumber:${build_validation_non_MU_script}", true, temporaryList) - echo "Non MU Repositories status code: ${res_non_MU_repositories}" - echoHtmlReportPath(build_validation_non_MU_script) - if (res_non_MU_repositories != 0) { - required_custom_channel_status[node] = 'FAIL' - error("Add common channels failed with status code: ${res_non_MU_repositories}") + withThrottle(muLockSlots, 5) { + echo 'Add non MU Repositories' + res_non_MU_repositories = runCucumberRakeTarget("cucumber:${build_validation_non_MU_script}", true, temporaryList) + echo "Non MU Repositories status code: ${res_non_MU_repositories}" + echoHtmlReportPath(build_validation_non_MU_script) + if (res_non_MU_repositories != 0) { + required_custom_channel_status[node] = 'FAIL' + error("Add common channels failed with status code: ${res_non_MU_repositories}") + } } } } @@ -922,4 +927,29 @@ def echoHtmlReportPath(String rake_target) { } } +@NonCPS +def tryAcquireSlot(slots, int max) { + int current = slots.get() + if (current < max) { + return slots.compareAndSet(current, current + 1) + } + return false +} + +@NonCPS +def releaseSlot(slots) { + slots.decrementAndGet() +} + +def withThrottle = { slots, int max = 5, Closure body -> + waitUntil { + tryAcquireSlot(slots, max) + } + try { + body() + } finally { + releaseSlot(slots) + } +} + return this