From 1b1b9fce22fae78e5e83d5610ac846d5f144a660 Mon Sep 17 00:00:00 2001 From: James Hardwick Date: Tue, 23 Sep 2014 11:44:38 -0700 Subject: [PATCH] support a custom regex for created views --- src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy | 5 +++-- src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy | 3 ++- src/main/groovy/com/entagen/jenkins/Main.groovy | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy b/src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy index d86852aa..b4185305 100644 --- a/src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy +++ b/src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy @@ -102,13 +102,14 @@ class JenkinsApi { post("job/${jobName}/doDelete") } - void createViewForBranch(BranchView branchView, String nestedWithinView = null) { + void createViewForBranch(BranchView branchView, String nestedWithinView = null, String viewRegex = null) { String viewName = branchView.viewName Map body = [name: viewName, mode: 'hudson.model.ListView', Submit: 'OK', json: '{"name": "' + viewName + '", "mode": "hudson.model.ListView"}'] println "creating view - viewName:${viewName}, nestedView:${nestedWithinView}" post(buildViewPath("createView", nestedWithinView), body) - body = [useincluderegex: 'on', includeRegex: "${branchView.templateJobPrefix}.*${branchView.safeBranchName}", name: viewName, json: '{"name": "' + viewName + '","useincluderegex": {"includeRegex": "' + branchView.templateJobPrefix + '.*' + branchView.safeBranchName + '"},' + VIEW_COLUMNS_JSON + '}'] + String regex = viewRegex ?: "${branchView.templateJobPrefix}.*${branchView.safeBranchName}" + body = [useincluderegex: 'on', includeRegex: regex, name: viewName, json: '{"name": "' + viewName + '","useincluderegex": {"includeRegex": "' + regex + '"},' + VIEW_COLUMNS_JSON + '}'] println "configuring view ${viewName}" post(buildViewPath("configSubmit", nestedWithinView, viewName), body) } diff --git a/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy b/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy index 80986eb1..b03bf45e 100644 --- a/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy +++ b/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy @@ -9,6 +9,7 @@ class JenkinsJobManager { String nestedView String jenkinsUrl String branchNameRegex + String viewRegex String jenkinsUser String jenkinsPassword @@ -124,7 +125,7 @@ class JenkinsJobManager { public void addMissingViews(List missingViews) { println "Missing views: $missingViews" for (BranchView missingView in missingViews) { - jenkinsApi.createViewForBranch(missingView, this.nestedView) + jenkinsApi.createViewForBranch(missingView, this.nestedView, this.viewRegex) } } diff --git a/src/main/groovy/com/entagen/jenkins/Main.groovy b/src/main/groovy/com/entagen/jenkins/Main.groovy index 5e7b1fa0..69c0c38c 100644 --- a/src/main/groovy/com/entagen/jenkins/Main.groovy +++ b/src/main/groovy/com/entagen/jenkins/Main.groovy @@ -16,6 +16,7 @@ class Main { d: [longOpt: 'dry-run', required: false, args: 0, argName: 'dryRun', description: "Dry run, don't actually modify, create, or delete any jobs, just print out what would happen - gradle flag: -DdryRun=true"], s: [longOpt: 'start-on-create', required: false, args: 0, argName: 'startOnCreate', description: "When creating a new job, start it at once."], v: [longOpt: 'no-views', required: false, args: 0, argName: 'noViews', description: "Suppress view creation - gradle flag -DnoViews=true"], + r: [longOpt: 'view-regex', required: false, args: 1, argName: 'viewRegex', description: "Supply a custom regex to be applied to any generated views, overriding the default template regex."], k: [longOpt: 'no-delete', required: false, args: 0, argName: 'noDelete', description: "Do not delete (keep) branches and views - gradle flag -DnoDelete=true"], f: [longOpt: 'filter-branch-names', required: false, args: 1, argName: 'branchNameRegex', description: "Only branches matching the regex will be accepted - gradle flag: -DbranchNameRegex="], usr: [longOpt: 'jenkins-user', required: false, args: 1, argName: 'jenkinsUser', description: "Jenkins username - gradle flag -DjenkinsUser="],