aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2018-07-18 16:31:26 -0400
committerGitHub <noreply@github.com>2018-07-18 16:31:26 -0400
commitf8db71695960795fa77ff45051df604d64ca2b1b (patch)
tree72e545ee5424ad158c0831980ad35f5e774d991d
parent76f29641e78d32d718de097aad7728fefc4e583f (diff)
downloadjscu_refactor-f8db71695960795fa77ff45051df604d64ca2b1b.tar.gz
Consolidate buildInfo into a single blob (#10)1.2.0
* Consolidate buildInfo into a single blob * Move DataConfig interactions inside of the test_cmds finally clause
-rw-r--r--src/DataConfig.groovy3
-rw-r--r--vars/utils.groovy114
2 files changed, 67 insertions, 50 deletions
diff --git a/src/DataConfig.groovy b/src/DataConfig.groovy
index bc19ae2..1107d17 100644
--- a/src/DataConfig.groovy
+++ b/src/DataConfig.groovy
@@ -6,6 +6,9 @@ class DataConfig implements Serializable {
String root = '.'
String server_id = ''
String match_prefix = '(.*)'
+ Boolean keep_data = false
+ int keep_builds = 20
+ int keep_days = 10
def data = [:]
DataConfig() {}
diff --git a/vars/utils.groovy b/vars/utils.groovy
index 2a7bb70..ed1716c 100644
--- a/vars/utils.groovy
+++ b/vars/utils.groovy
@@ -44,12 +44,11 @@ def scm_checkout(skip_disable=false) {
def run(configs, concurrent = true) {
def tasks = [:]
for (config in configs) {
-
def BuildConfig myconfig = new BuildConfig() // MUST be inside for loop.
myconfig = SerializationUtils.clone(config)
-
def config_name = ""
config_name = config.name
+
// For staged deprecation of '.build_mode' in favor of '.name'.
// TODO: Remove once all Jenkinsfiles are converted.
if (myconfig.build_mode != "") {
@@ -148,6 +147,67 @@ def run(configs, concurrent = true) {
}
}
finally {
+ // Perform Artifactory upload if required
+ if (myconfig.test_configs.size() > 0) {
+ stage("Artifactory (${myconfig.name})") {
+ def buildInfo = Artifactory.newBuildInfo()
+
+ buildInfo.env.capture = true
+ buildInfo.env.collect()
+ def server
+
+ for (artifact in myconfig.test_configs) {
+ server = Artifactory.server artifact.server_id
+
+ // 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')) {
+ 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 ->
+ def bi_temp = server.upload spec: blob.value
+
+ // Define retention scheme
+ // Defaults: see DataConfig.groovy
+ bi_temp.retention \
+ maxBuilds: artifact.keep_builds, \
+ maxDays: artifact.keep_days, \
+ deleteBuildArtifacts: !artifact.keep_data
+
+ buildInfo.append bi_temp
+ }
+
+ } // end for-loop
+
+ server.publishBuildInfo buildInfo
+
+ } // end stage Artifactory
+ } // end test_configs check
+
// If a non-JUnit format .xml file exists in the
// root of the workspace, the XUnitBuilder report
// ingestion will fail.
@@ -163,54 +223,8 @@ def run(configs, concurrent = true) {
} else {
println("No .xml files found in workspace. Test report ingestion skipped.")
}
- }
- }
-
- 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 test test_cmd finally clause
+ } // end stage test_cmd
} // end withEnv
} // end node
} //end tasks