Skip to content

Commit

Permalink
Merge pull request entagen#70 from entagen/jamesdh/custom_view_regex
Browse files Browse the repository at this point in the history
Custom View Regex
  • Loading branch information
ebakke committed Sep 23, 2014
2 parents af18a93 + 48b72be commit f40cafa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
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 - gradle flag: -DviewRegex=<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 f40cafa

Please sign in to comment.