test-salt-model: only test affected cluster if testing from gerrit patchset
Change-Id: I741b17c72cdbba4f2b8510ece6e537ce82d7eaa0
diff --git a/test-salt-models-pipeline.groovy b/test-salt-models-pipeline.groovy
index 2ff76d2..dcb70f9 100644
--- a/test-salt-models-pipeline.groovy
+++ b/test-salt-models-pipeline.groovy
@@ -83,6 +83,15 @@
def infraYMLs = sh(script: "find ./classes/ -regex '.*cluster/[-_a-zA-Z0-9]*/[infra/]*init\\.yml' -exec grep -il 'cluster_name' {} \\;", returnStdout: true).tokenize()
def branches = [:]
def acc = 0
+
+ def modifiedClusters = null
+ if (gerritRef) {
+ checkChange = sh(script: "git diff-tree --no-commit-id --name-only -r HEAD | grep -v classes/cluster", returnStatus: true)
+ if (checkChange == 1) {
+ modifiedClusters = sh(script: "git diff-tree --no-commit-id --name-only -r HEAD | grep classes/cluster/ | awk -F/ '{print \$3}' | uniq", returnStdout: true).tokenize()
+ }
+ }
+
for (int i = 0; i < infraYMLs.size(); i++) {
def infraYMLConfig = readYaml(file: infraYMLs[i])
if(!infraYMLConfig["parameters"].containsKey("_param")){
@@ -104,6 +113,10 @@
acc = 0
}
+ if (gerritRef && modifiedClusters && !modifiedClusters.contains(clusterName)) {
+ continue
+ }
+
branches[testTarget] = {
build job: "test-salt-model-node", parameters: [
[$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: defaultGitUrl],
@@ -134,3 +147,4 @@
}
}
+x
\ No newline at end of file