diff --git a/build.gradle b/build.gradle index a0134abf..9b86920c 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ task syncWithRepo(dependsOn: 'classes', type: JavaExec) { main = 'com.entagen.jenkins.Main' classpath = sourceSets.main.runtimeClasspath // pass through specified system properties to the call to main - ['help', 'jenkinsUrl', 'jenkinsUser', 'jenkinsPassword', 'gitUrl', 'templateJobPrefix', 'templateBranchName', 'branchNameRegex', 'nestedView', 'printConfig', 'dryRun', 'startOnCreate', 'noViews', 'noDelete'].each { + ['help', 'jenkinsUrl', 'jenkinsUser', 'jenkinsPassword', 'gitUrl', 'templateJobPrefix', 'templateBranchName', 'branchNameRegex', 'nestedView', 'viewRegex', 'printConfig', 'dryRun', 'startOnCreate', 'noViews', 'noDelete'].each { if (System.getProperty(it)) systemProperty it, System.getProperty(it) } 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..50a99a4f 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 - gradle flag: -DviewRegex="], 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="],