Skip to content

Commit

Permalink
support a custom regex for created views
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdh committed Sep 23, 2014
1 parent af18a93 commit 1b1b9fc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class JenkinsJobManager {
String nestedView
String jenkinsUrl
String branchNameRegex
String viewRegex
String jenkinsUser
String jenkinsPassword

Expand Down Expand Up @@ -124,7 +125,7 @@ class JenkinsJobManager {
public void addMissingViews(List<BranchView> missingViews) {
println "Missing views: $missingViews"
for (BranchView missingView in missingViews) {
jenkinsApi.createViewForBranch(missingView, this.nestedView)
jenkinsApi.createViewForBranch(missingView, this.nestedView, this.viewRegex)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/groovy/com/entagen/jenkins/Main.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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=<regex>"],
usr: [longOpt: 'jenkins-user', required: false, args: 1, argName: 'jenkinsUser', description: "Jenkins username - gradle flag -DjenkinsUser=<jenkinsUser>"],
Expand Down

0 comments on commit 1b1b9fc

Please sign in to comment.