Add checkDependencyJobs
PRODX-1400
Change-Id: Ic1daa7e1629d328fb78a03b2ffe69c87184777f4
diff --git a/src/com/mirantis/mk/JenkinsUtils.groovy b/src/com/mirantis/mk/JenkinsUtils.groovy
index 4513f2d..780ccab 100644
--- a/src/com/mirantis/mk/JenkinsUtils.groovy
+++ b/src/com/mirantis/mk/JenkinsUtils.groovy
@@ -231,3 +231,43 @@
}
return buildsMap
}
+
+/**
+ * Check dependency jobs passed successfully
+
+ * @param block (bool) Block child jobs in case of parent dependencies failed
+ * @return (map)[
+ * status: (bool) True if there are no failed dependencies
+ * log: (string) Verbose description
+ * ]
+ */
+def checkDependencyJobs(block = true) {
+ def common = new com.mirantis.mk.Common()
+ depList = []
+ if (env.TRIGGER_DEPENDENCY_KEYS){
+ common.infoMsg('Job may depends on parent jobs, check if dependency jobs exist...')
+ depKeys = env.TRIGGER_DEPENDENCY_KEYS.toString()
+ depList = depKeys.split()
+ if (depList){
+ common.infoMsg('Here is dependency jobs-list: ' + depList)
+ for (String item : depList) {
+ prjName = item.replaceAll('[^a-zA-Z0-9]+', '_')
+ triggerResult = 'TRIGGER_' + prjName.toUpperCase() + '_BUILD_RESULT'
+ triggerJobName = 'TRIGGER_' + prjName.toUpperCase() + '_BUILD_NAME'
+ triggerJobBuild = 'TRIGGER_' + prjName.toUpperCase() + '_BUILD_NUMBER'
+ if (env.getProperty(triggerResult) != 'SUCCESS'){
+ msg = "Dependency job ${env.getProperty(triggerJobName)} #${env.getProperty(triggerJobBuild)} is ${env.getProperty(triggerResult)}"
+ common.warningMsg(msg)
+ if (block){
+ currentBuild.result = 'NOT_BUILT'
+ currentBuild.description = msg
+ }
+ return [status: false, log: msg, jobs: depList]
+ }
+ }
+ }
+ } else {
+ common.infoMsg('There is no job-dependencies')
+ }
+ return [status: true, log: '', jobs: depList]
+}