Permalink
Browse files

commit of patch created from jbbrwcky/jenkins-build-per-branch jabbrw…

  • Loading branch information...
1 parent 61a92c2 commit 48b099b715113cee87054e05d3552eb871de2b99 @tednaleid tednaleid committed Jun 18, 2012
View
@@ -2,7 +2,9 @@
*.iml
*.ipr
*.iws
+*.diff
build
.gradle
-out/
+out
+atlassian-ide-plugin.xml
View
@@ -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', 'gitUrl', 'templateJobPrefix', 'templateBranchName', 'nestedView', 'printConfig', 'dryRun'].each {
+ ['help', 'jenkinsUrl', 'gitUrl', 'templateJobPrefix', 'templateBranchName', 'nestedView', 'printConfig', 'dryRun', 'branchNameRegex'].each {
if (System.getProperty(it)) systemProperty it, System.getProperty(it)
}
@@ -1,7 +1,10 @@
package com.entagen.jenkins
+import java.util.regex.Pattern
+
class GitApi {
String gitUrl
+ Pattern branchNameFilter = ~/.+/
public List<String> getBranchNames() {
String command = "git ls-remote --heads ${gitUrl}"
@@ -13,7 +16,7 @@ class GitApi {
// ex: b9c209a2bf1c159168bf6bc2dfa9540da7e8c4a26\trefs/heads/master
String branchNameRegex = "^.*\trefs/heads/(.*)\$"
String branchName = line.find(branchNameRegex) { full, branchName -> branchName }
- if (branchName) branchNames << branchName
+ if (branchName && branchNameFilter.matcher(branchName).matches()) branchNames << branchName
}
return branchNames
@@ -1,11 +1,15 @@
package com.entagen.jenkins
+import java.util.regex.Pattern
+
class JenkinsJobManager {
String templateJobPrefix
String templateBranchName
String gitUrl
String nestedView
String jenkinsUrl
+ String branchNameRegex
+
Boolean dryRun = false
JenkinsApi jenkinsApi
@@ -141,6 +145,7 @@ class JenkinsJobManager {
if (!gitApi) {
assert gitUrl != null
this.gitApi = new GitApi(gitUrl: gitUrl)
+ gitApi.branchNameFilter = Pattern.compile(this.branchNameRegex)
}
return this.gitApi
@@ -13,7 +13,8 @@ class Main {
t: [longOpt: 'template-branch', required: true, args: 1, argName: 'templateBranchName', description: "Template Branch Name - gradle flag -DtemplateBranchName=<branchName>"],
n: [longOpt: 'nested-view', required: false, args: 1, argName: 'nestedView', description: "Nested Parent View Name - gradle flag -DnestedView=<nestedView> - optional - must have Jenkins Nested View Plugin installed"],
c: [longOpt: 'print-config', required: false, args: 0, argName: 'printConfig', description: "Check configuration - print out settings then exit - gradle flag -DprintConfig=true"],
- 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"]
+ 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"],
+ f: [longOpt: 'filter-branch-names', required: false, args: 1, argName: 'branchNameRegex', description: "Only branches matching the regex will be accepted - gradle flag: -DbranchNameRegex=<regex>"],
]
public static void main(String[] args) {
@@ -37,6 +37,22 @@ garbage line that should be ignored
assert ["master", "release_1.0rc1", "ted/feature_branch"] == branchNames.sort()
}
+ @Test public void testGetFilteredBranchNames() {
+ String mockResult = """
+10b42258f451ebf2640d3c18850e0c22eecdad4\trefs/heads/feature/myfeature
+b9c209a2bf1c159168bf6bc2dfa9540da7e8c4a26\trefs/heads/master
+abd856d2ae658ee5f14889b465f3adcaf65fb52b\trefs/heads/release/1.0rc1
+abd856d2ae658ee5f14889b465f3adcaf65fb52b\trefs/heads/other_branch
+ """.trim()
+
+ GitApi gitApi = new GitApiMockedResult(mockResult: mockResult)
+
+ gitApi.branchNameFilter = ~/feature\/.+|release\/.+|master/
+ List<String> branchNames = gitApi.branchNames
+
+ assert ["feature/myfeature", "master", "release/1.0rc1"] == branchNames.sort()
+ }
+
}

0 comments on commit 48b099b

Please sign in to comment.