forked from jcanal-sap/crc-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crc-scripts-executor.groovy
29 lines (21 loc) · 1.08 KB
/
crc-scripts-executor.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import org.apache.commons.io.FilenameUtils
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
// dependencies are available in SAP Commerce environment
// please run script in hac groovy console
def baseUrl = 'raw.githubusercontent.com/sap-onestrike/crc-scripts/main/scripts'
def includeScripts = []
def scriptsList = "https://${baseUrl}/list.txt?${System.currentTimeMillis()}".toURL().text.split("\r\n*")
def js = new JsonSlurper()
def results = []
println "scripts: ${scriptsList.join(', ')}"
scriptsList*.trim().each { s ->
if (s && (includeScripts.isEmpty() || s in includeScripts)) {
def sc = remoteScriptsRepository.lookupScript('https', "${baseUrl}/${s}")
def name = FilenameUtils.getBaseName(s)
println "running '${name}'..."
def res = scriptingLanguagesExecutor.executeScript(sc.engineName, sc.content, false)
results << [ 'name': name, 'ok': !((res.stacktraceText?.trim()) as boolean), 'result': js.parseText(res.executionResult), 'error': res.stacktraceText ]
}
}
JsonOutput.prettyPrint(JsonOutput.toJson(results))