diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2018-06-13 12:29:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-13 12:29:09 -0400 |
commit | aef51d1481afd3e8d1efb9ef273a80a26167d368 (patch) | |
tree | dd27ab116d035e3fc2443fa9fa62ed4085582cb1 | |
parent | 63a8108afd06753d595a703273afb35d58543dd8 (diff) | |
parent | e0e0a75cb2085584eb50e6cff841c75cd39471fd (diff) | |
download | jscu_refactor-aef51d1481afd3e8d1efb9ef273a80a26167d368.tar.gz |
Merge pull request #6 from jhunkeler/dataconfig2
Implement DataConfig
-rw-r--r-- | src/BuildConfig.groovy | 1 | ||||
-rw-r--r-- | src/DataConfig.groovy | 22 | ||||
-rw-r--r-- | vars/utils.groovy | 55 |
3 files changed, 75 insertions, 3 deletions
diff --git a/src/BuildConfig.groovy b/src/BuildConfig.groovy index 1eb98be..a954c22 100644 --- a/src/BuildConfig.groovy +++ b/src/BuildConfig.groovy @@ -12,6 +12,7 @@ class BuildConfig implements Serializable { def env_vars_raw = [] def build_cmds = [] def test_cmds = [] + def test_configs = [] def failedFailureNewThresh = '' def failedFailureThresh = '' diff --git a/src/DataConfig.groovy b/src/DataConfig.groovy new file mode 100644 index 0000000..bc19ae2 --- /dev/null +++ b/src/DataConfig.groovy @@ -0,0 +1,22 @@ +package DataConfig; +import groovy.json.JsonOutput +import org.apache.commons.io.FileUtils + +class DataConfig implements Serializable { + String root = '.' + String server_id = '' + String match_prefix = '(.*)' + def data = [:] + + DataConfig() {} + + def insert(String name, String block) { + /* Store JSON directly as string */ + this.data[name] = block + } + + def insert(String name, block=[:]) { + /* Convert a Groovy Map to JSON and store it */ + this.data[name] = JsonOutput.toJson(block) + } +} diff --git a/vars/utils.groovy b/vars/utils.groovy index 888e467..2a7bb70 100644 --- a/vars/utils.groovy +++ b/vars/utils.groovy @@ -1,6 +1,9 @@ // Jenkinsfile support utilities import BuildConfig.BuildConfig +import groovy.io.FileType +import groovy.json.JsonOutput import org.apache.commons.lang3.SerializationUtils +import org.apache.commons.io.FilenameUtils // Clone the source repository and examine the most recent commit message. @@ -162,6 +165,52 @@ def run(configs, concurrent = true) { } } } + + if (myconfig.test_configs.size() > 0) { + stage("Artifactory (${myconfig.build_mode})") { + println("Scanning for directives...") + for (artifact in myconfig.test_configs) { + + // Construct absolute path to data + def path = FilenameUtils.getFullPath( + "${env.WORKSPACE}/${artifact.root}" + ) + + // Record listing of all files starting at ${path} + // (Native Java and Groovy approaches will not work here) + sh(script: "find ${path} -type f", + returnStdout: true).trim().tokenize('\n').each { + + // Semi-wildcard matching of JSON input files + // ex: + // it = "test_1234_result.json" + // artifact.match_prefix = "(.*)_result" + // + // pattern becomes: (.*)_result(.*)\\.json + if (it.matches( + artifact.match_prefix + '(.*)\\.json')) { + println("Reading: ${it}") + def basename = FilenameUtils.getBaseName(it) + def data = readFile(it) + + // Store JSON in a logical map + // i.e. ["basename": [data]] + artifact.insert(basename, data) + } + } // end find.each + + // Submit each request to the Artifactory server + artifact.data.each { blob -> + println("Ingesting: ${blob.key}") + println(JsonOutput.prettyPrint(blob.value)) + def server = Artifactory.server artifact.server_id + def buildInfo = server.upload spec: blob.value + server.publishBuildInfo buildInfo + } + + } // end for-loop + } // end stage Artifactory + } // end test_configs for-loop } // end withEnv } // end node } //end tasks @@ -174,10 +223,10 @@ def run(configs, concurrent = true) { } } else { // Run tasks sequentially. Any failure halts the sequence. - def iter = 0 - tasks.each{ key, value -> + def iter = 0 + for (task in tasks) { def localtask = [:] - localtask[key] = tasks[key] + localtask[task.key] = task.value stage("Serial-${iter}") { parallel(localtask) } |