Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Allow builds without a prefix #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/groovy/com/entagen/jenkins/BranchView.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion src/main/groovy/com/entagen/jenkins/JenkinsApi.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 12 additions & 1 deletion src/main/groovy/com/entagen/jenkins/JenkinsJobManager.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ class JenkinsJobManager {
}

List<TemplateJob> findRequiredTemplateJobs(List<String> allJobNames) {
String regex = /^($templateJobPrefix-[^-]*)-($templateBranchName)$/
String regex = ""
if(templateJobPrefix) {
regex = /^($templateJobPrefix-[^-]*)-($templateBranchName)$/
}
else {
regex = /^([^-]*)-($templateBranchName)$/
}

List<TemplateJob> templateJobs = allJobNames.findResults { String jobName ->
TemplateJob templateJob = null
Expand Down Expand Up @@ -129,7 +135,12 @@ class JenkinsJobManager {
}

public List<String> getDeprecatedViewNames(List<String> existingViewNames, List<BranchView> expectedBranchViews) {
if(this.templateJobPrefix) {
return existingViewNames?.findAll { it.startsWith(this.templateJobPrefix) } - expectedBranchViews?.viewName ?: []
}
else {
return existingViewNames - expectedBranchViews?.viewName ?: []
}
}

public void deleteDeprecatedViews(List<String> deprecatedViewNames) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/com/entagen/jenkins/Main.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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=<jenkinsUrl>"],
u: [longOpt: 'git-url', required: true, args: 1, argName: 'gitUrl', description: "Git Repository URL - gradle flag -DgitUrl=<gitUrl>"],
p: [longOpt: 'job-prefix', required: true, args: 1, argName: 'templateJobPrefix', description: "Template Job Prefix, - gradle flag -DtemplateJobPrefix=<jobPrefix>"],
p: [longOpt: 'job-prefix', required: false, args: 1, argName: 'templateJobPrefix', description: "Template Job Prefix, - gradle flag -DtemplateJobPrefix=<jobPrefix>"],
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"],
Expand Down