Skip to content

Commit d165166

Browse files
Thomas Michaelschnatterer
authored andcommitted
Refactor: ignoreJenkins to createJenkinsJob
Creating jenkins jobs is more of an edge case. Searching all files in all branches is expensive. Lets only do it if required.
1 parent 9554be6 commit d165166

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

docs/configuration.schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@
164164
"items" : {
165165
"type" : "object",
166166
"properties" : {
167-
"ignoreJenkins" : {
167+
"createJenkinsJob" : {
168168
"type" : [ "boolean", "null" ],
169-
"description" : "If true, no Jenkinsjob will be created."
169+
"description" : "If true, creates a Jenkins job, if jenkinsfile exists in one of the content repo's branches."
170170
},
171171
"overwriteMode" : {
172172
"anyOf" : [ {
@@ -175,7 +175,7 @@
175175
"type" : "string",
176176
"enum" : [ "INIT", "RESET", "UPGRADE" ]
177177
} ],
178-
"description" : "This defines, how customer repos will be updated.\nINIT - push only if repo does not exist.\nRESET - delete all files after cloning source - files not in content are deleted\nUPGRADE - clone and copy - existing files will be overwritten, files not in content are kept"
178+
"description" : "This defines, how customer repos will be updated.\nINIT - push only if repo does not exist.\nRESET - delete all files after cloning source - files not in content are deleted\nUPGRADE - clone and copy - existing files will be overwritten, files not in content are kept. For type: MIRROR reset and upgrade have same result: in both cases source repo will be force pushed to target repo."
179179
},
180180
"password" : {
181181
"type" : [ "string", "null" ],

src/main/groovy/com/cloudogu/gitops/config/Config.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ class Config {
135135
@JsonPropertyDescription(CONTENT_REPO_TARGET_DESCRIPTION)
136136
String target = ''
137137

138-
@JsonPropertyDescription(CONTENT_REPO_TARGET_OVERWRITE_MODE)
138+
@JsonPropertyDescription(CONTENT_REPO_TARGET_OVERWRITE_MODE_DESCRIPTION)
139139
OverwriteMode overwriteMode = OverwriteMode.INIT // Defensively use init to not override existing files by default
140140

141-
@JsonPropertyDescription(CONTENT_REPO_IGNORE_JENKINS)
142-
Boolean ignoreJenkins = false
141+
@JsonPropertyDescription(CONTENT_REPO_CREATE_JENKINS_JOB_DESCRIPTION)
142+
Boolean createJenkinsJob = false
143143
}
144144
}
145145

@@ -806,7 +806,7 @@ class Config {
806806

807807
/**
808808
* This defines, how customer repos will be updated.
809-
* See {@link ConfigConstants#CONTENT_REPO_TARGET_OVERWRITE_MODE}
809+
* See {@link ConfigConstants#CONTENT_REPO_TARGET_OVERWRITE_MODE_DESCRIPTION}
810810
*/
811811
static enum OverwriteMode {
812812
INIT, RESET, UPGRADE

src/main/groovy/com/cloudogu/gitops/config/ConfigConstants.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ interface ConfigConstants {
4040
String CONTENT_REPO_TEMPLATING_DESCRIPTION = "When true, template all files ending in .ftl within the repo"
4141
String CONTENT_REPO_TYPE_DESCRIPTION = "Content Repos can either be:\ncopied (only the files, starting on ref, starting at path within the repo. Requires target)\n, mirrored (FORCE pushes ref or the whole git repo if no ref set). Requires target, does not allow path and template.)\nfolderBased (folder structure is interpreted as repos. That is, root folder becomes namespace in SCM, sub folders become repository names in SCM, files are copied. Requires target.)"
4242
String CONTENT_REPO_TARGET_DESCRIPTION = "Target repo for the repository in the for of namespace/name. Must contain one slash to separate namespace from name."
43-
String CONTENT_REPO_TARGET_OVERWRITE_MODE = "This defines, how customer repos will be updated.\nINIT - push only if repo does not exist.\nRESET - delete all files after cloning source - files not in content are deleted\nUPGRADE - clone and copy - existing files will be overwritten, files not in content are kept"
44-
String CONTENT_REPO_IGNORE_JENKINS = "If true, no Jenkinsjob will be created."
43+
String CONTENT_REPO_TARGET_OVERWRITE_MODE_DESCRIPTION = "This defines, how customer repos will be updated.\nINIT - push only if repo does not exist.\nRESET - delete all files after cloning source - files not in content are deleted\nUPGRADE - clone and copy - existing files will be overwritten, files not in content are kept. For type: MIRROR reset and upgrade have same result: in both cases source repo will be force pushed to target repo."
44+
String CONTENT_REPO_CREATE_JENKINS_JOB_DESCRIPTION = "If true, creates a Jenkins job, if jenkinsfile exists in one of the content repo's branches."
4545
String CONTENT_VARIABLES_DESCRIPTION = "Additional variables to use in custom templates."
4646

4747
// group jenkins

src/main/groovy/com/cloudogu/gitops/features/Content.groovy

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,7 @@ class Content extends Feature {
363363
}
364364

365365
private void createJenkinsJob(RepoCoordinate repoCoordinate, ScmmRepo repo) {
366-
// easy condition
367-
if (!repoCoordinate.repoConfig.ignoreJenkins && jenkins.isEnabled()) {
368-
// this conditions iterates over all branches
366+
if (repoCoordinate.repoConfig.createJenkinsJob && jenkins.isEnabled()) {
369367
if (existFileInSomeBranch(repo.absoluteLocalRepoTmpDir, 'Jenkinsfile')) {
370368
jenkins.createJenkinsjob(repoCoordinate.namespace, repoCoordinate.namespace)
371369
}

src/test/groovy/com/cloudogu/gitops/features/ContentTest.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ class ContentTest {
749749
* file content after that should be: nonFolderRepo1
750750
*/
751751
config.content.repos = [
752-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1'), ref: 'main', type: ContentRepoType.COPY, ignoreJenkins: false, target: 'common/repo'),
752+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1'), ref: 'main', type: ContentRepoType.COPY, createJenkinsJob: true, target: 'common/repo'),
753753
]
754754
scmmApiClient.mockRepoApiBehaviour()
755755
when(jenkins.isEnabled()).thenReturn(true)
@@ -768,10 +768,10 @@ class ContentTest {
768768
* file content after that should be: nonFolderRepo1
769769
*/
770770
config.content.repos = [
771-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1'), ref: 'main', type: ContentRepoType.COPY, ignoreJenkins: true, target: 'common/repo'),
771+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1'), ref: 'main', type: ContentRepoType.COPY, createJenkinsJob: false, target: 'common/repo'),
772772
]
773773
scmmApiClient.mockRepoApiBehaviour()
774-
when(jenkins.isEnabled()).thenReturn(true)
774+
when(jenkins.isEnabled()).thenReturn(false)
775775
createContent().install()
776776
verify(jenkins, never()).createJenkinsjob(any(), any())
777777
}
@@ -787,7 +787,7 @@ class ContentTest {
787787
* file content after that should be: nonFolderRepo1
788788
*/
789789
config.content.repos = [
790-
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1'), ref: 'main', type: ContentRepoType.COPY, ignoreJenkins: false, target: 'common/repo'),
790+
new ContentRepositorySchema(url: createContentRepo('nonFolderBasedRepo1'), ref: 'main', type: ContentRepoType.COPY, createJenkinsJob: false, target: 'common/repo'),
791791
]
792792
def response = scmmApiClient.mockSuccessfulResponse(201)
793793
when(scmmApiClient.repositoryApi.create(any(Repository), anyBoolean())).thenReturn(response)

0 commit comments

Comments
 (0)