DK
Size: a a a
DK
t
M
t
M
AK
AK
Н
ММ
Н
ММ
Н
ММ
u
u
u
import groovy.json.JsonOutput
def call(def cerediraTess, def creds, List agentsList, def scriptName, List arguments = [], Closure check = {}, int retryNumber = 3, int timeoutSeconds = 900) {
def parallelTasks = [:]
for (int i = 0; i < agentsList.size(); i++) {
// Нельзя выносить вычисление этого значения внутрь вызова httpPostRequest, потому что тот блок вычисляется в отдельных потоках
// и там значение i будет последним из цикла всегда, и будет вываливаться ошибка OutOfBoundException
def requestBody = JsonOutput.toJson([ 'hostname': agentsList[i].name, 'args': arguments, 'timeout': timeoutSeconds as int])
parallelTasks["Выполнение ${scriptName} на ${agentsList[i].name}"] = {
retry(retryNumber) {
withCredentials([usernameColonPassword(credentialsId: creds, variable: 'ct_auth')]) {
def res = httpPostRequest("${cerediraTess}/executeScript/${scriptName}", requestBody, [[maskValue: true, name: 'Authorization', value: "Basic " + "${ct_auth}".bytes.encodeBase64().toString()]], timeoutSeconds)
check.call(res)
}
}
}
}
parallel parallelTasks
}
u
t
t
t