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/JenkinsApi.groovy b/src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy index ff242bce..498dd864 100644 --- a/src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy +++ b/src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy @@ -105,7 +105,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 80986eb1..9abe963a 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 @@ -129,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) { 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"],