From cd8f690bdedbb43df8d41ec489f2512b2da4c06f Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 12 Nov 2012 13:36:53 +0000 Subject: [PATCH 1/4] mark templateJobPrefix as not required --- src/main/groovy/com/entagen/jenkins/Main.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/com/entagen/jenkins/Main.groovy b/src/main/groovy/com/entagen/jenkins/Main.groovy index 5e7b1fa0..0da111e1 100644 --- a/src/main/groovy/com/entagen/jenkins/Main.groovy +++ b/src/main/groovy/com/entagen/jenkins/Main.groovy @@ -9,7 +9,7 @@ class Main { h: [longOpt: 'help', required: false, args: 0, argName: 'help', description: "Print usage information - gradle flag -Dhelp=true"], j: [longOpt: 'jenkins-url', required: true, args: 1, argName: 'jenkinsUrl', description: "Jenkins URL - gradle flag -DjenkinsUrl="], u: [longOpt: 'git-url', required: true, args: 1, argName: 'gitUrl', description: "Git Repository URL - gradle flag -DgitUrl="], - p: [longOpt: 'job-prefix', required: true, args: 1, argName: 'templateJobPrefix', description: "Template Job Prefix, - gradle flag -DtemplateJobPrefix="], + p: [longOpt: 'job-prefix', required: false, args: 1, argName: 'templateJobPrefix', description: "Template Job Prefix, - gradle flag -DtemplateJobPrefix="], t: [longOpt: 'template-branch', required: true, args: 1, argName: 'templateBranchName', description: "Template Branch Name - gradle flag -DtemplateBranchName="], n: [longOpt: 'nested-view', required: false, args: 1, argName: 'nestedView', description: "Nested Parent View Name - gradle flag -DnestedView= - 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"], From ede75377115b62227c9c960f796dd488016db3e3 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 12 Nov 2012 13:41:03 +0000 Subject: [PATCH 2/4] run without prefix --- src/main/groovy/com/entagen/jenkins/BranchView.groovy | 7 ++++++- .../groovy/com/entagen/jenkins/JenkinsJobManager.groovy | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/com/entagen/jenkins/BranchView.groovy b/src/main/groovy/com/entagen/jenkins/BranchView.groovy index f392a67b..d6cf5d22 100644 --- a/src/main/groovy/com/entagen/jenkins/BranchView.groovy +++ b/src/main/groovy/com/entagen/jenkins/BranchView.groovy @@ -5,7 +5,12 @@ class BranchView { String branchName public String getViewName() { - return "$templateJobPrefix-$safeBranchName" + if(templateJobPrefix) { + return "$templateJobPrefix-$safeBranchName" + } + else { + return safeBranchName + } } public String getSafeBranchName() { diff --git a/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy b/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy index 80986eb1..11640c37 100644 --- a/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy +++ b/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy @@ -94,7 +94,13 @@ class JenkinsJobManager { } List findRequiredTemplateJobs(List allJobNames) { - String regex = /^($templateJobPrefix-[^-]*)-($templateBranchName)$/ + String regex = "" + if(templateJobPrefix) { + regex = /^($templateJobPrefix-[^-]*)-($templateBranchName)$/ + } + else { + regex = /^([^-]*)-($templateBranchName)$/ + } List templateJobs = allJobNames.findResults { String jobName -> TemplateJob templateJob = null From 82b50bc9982fca19cde6cc7d35c55251047ff1c8 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 12 Nov 2012 14:07:35 +0000 Subject: [PATCH 3/4] more hacks around prefix name --- src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy | 7 ++++++- .../groovy/com/entagen/jenkins/JenkinsJobManager.groovy | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy b/src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy index e5bdc589..6db05520 100644 --- a/src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy +++ b/src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy @@ -102,7 +102,12 @@ class JenkinsApi { 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 + '}'] + if(branchView.templateJobPrefix) { + body = [useincluderegex: 'on', includeRegex: "${branchView.templateJobPrefix}.*${branchView.safeBranchName}", name: viewName, json: '{"name": "' + viewName + '","useincluderegex": {"includeRegex": "' + branchView.templateJobPrefix + '.*' + branchView.safeBranchName + '"},' + VIEW_COLUMNS_JSON + '}'] + } + else { + body = [useincluderegex: 'on', includeRegex: ".*${branchView.safeBranchName}", name: viewName, json: '{"name": "' + viewName + '","useincluderegex": {"includeRegex": "' + '.*' + branchView.safeBranchName + '"},' + 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 11640c37..038ecbbd 100644 --- a/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy +++ b/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy @@ -135,7 +135,12 @@ class JenkinsJobManager { } public List getDeprecatedViewNames(List existingViewNames, List expectedBranchViews) { + if(this.templateJobPrefix) { return existingViewNames?.findAll { it.startsWith(this.templateJobPrefix) } - expectedBranchViews?.viewName ?: [] + } + else { + return existingViewNames? - expectedBranchViews?.viewName ?: [] + } } public void deleteDeprecatedViews(List deprecatedViewNames) { From 54c13ab4959090b21d57accaad0e4a0538373780 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 12 Nov 2012 14:09:38 +0000 Subject: [PATCH 4/4] spoilers: I don't actually know groovy --- src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy b/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy index 038ecbbd..9abe963a 100644 --- a/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy +++ b/src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy @@ -139,7 +139,7 @@ class JenkinsJobManager { return existingViewNames?.findAll { it.startsWith(this.templateJobPrefix) } - expectedBranchViews?.viewName ?: [] } else { - return existingViewNames? - expectedBranchViews?.viewName ?: [] + return existingViewNames - expectedBranchViews?.viewName ?: [] } }