diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2018-12-17 21:41:33 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2018-12-17 21:41:33 -0500 |
commit | 0930b9ebd404c20a96ac78de6f2e8640eca129e9 (patch) | |
tree | 2a4eecb8ffbd93dffb89d31378a308430555f76d | |
download | jenkins_shl-0930b9ebd404c20a96ac78de6f2e8640eca129e9.tar.gz |
Initial commit
-rw-r--r-- | src/edu/stsci/DataConfig.groovy | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/edu/stsci/DataConfig.groovy b/src/edu/stsci/DataConfig.groovy new file mode 100644 index 0000000..c7db504 --- /dev/null +++ b/src/edu/stsci/DataConfig.groovy @@ -0,0 +1,86 @@ +package edu.stsci +import groovy.json.JsonOutput +import org.apache.commons.io.FileUtils + +class DataConfig implements Serializable { + String root = '.' + String server_ident = '' + String match_prefix = '(.*)' + Boolean keep_data = false + int keep_builds = 20 + int keep_days = 10 + def steps + def server_conn + String server_ident + String path + def data = [:] + def buildInfo + + DataConfig(steps, server_ident) { + this.steps = steps + this.server_ident = server_ident + this.server_conn = Artifactory.server(this.server_ident) + this.buildInfo = Artifactory.newBuildInfo() + this.buildInfo.env.capture = true + this.buildInfo.env.collect() + // Construct absolute path to data + this.scan_path = FilenameUtils.getFullPath( + "${this.steps.env.WORKSPACE}/${this.root}" + ) + } + + 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) + } + + def populate() { + // Record listing of all files starting at ${path} + // (Native Java and Groovy approaches will not + // work here) + this.steps.sh(script: "find ${this.scan_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( + this.match_prefix + '(.*)\\.json')) { + def basename = FilenameUtils.getBaseName(it) + def data = readFile(it) + + // Store JSON in a logical map + // i.e. ["basename": [data]] + this.insert(basename, data) + } + } // end find.each + } + + def run() { + this.populate() + + // Submit each request to the Artifactory server + this.data.each { blob -> + def spec = this.server_conn.upload(spec: blob.value) + this.buildInfo.append(spec) + } + + // Define retention scheme + // Defaults: see DataConfig.groovy + this.buildInfo.retention \ + maxBuilds: this.keep_builds, \ + maxDays: this.keep_days, \ + deleteBuildArtifacts: !this.keep_data + + this.server_conn.publishBuildInfo this.buildInfo + + } // end stage Artifactory +} |