Skip to content

Commit

Permalink
draft: squash: Add seed job
Browse files Browse the repository at this point in the history
  • Loading branch information
turboBasic committed Dec 29, 2023
1 parent 4afa43a commit af257f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
31 changes: 21 additions & 10 deletions jobs/Admin/seed/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import javaposse.jobdsl.plugin.LookupStrategy


withNode {
stage('checkout') {
checkout scm
Expand All @@ -23,7 +26,7 @@ void withNode(Closure body) {
}

List<String> getDslFiles() {
findFiles(glob: 'jobs/**/Jenkinsfile.dsl')
findFiles(glob: "${getJobsPrefix()}**/Jenkinsfile.dsl")
.findAll { !it.directory }
.collect { it.path }
.toSorted()
Expand All @@ -32,7 +35,7 @@ List<String> getDslFiles() {
List<String> getJobFolders() {
getDslFiles()
.collect {
it.replaceFirst('^jobs/', '')
it.replaceFirst("^${getJobsPrefix()}", '')
.replaceFirst('([^/]+/)?Jenkinsfile[.]dsl$', '')
.replaceFirst('/$', '')
}
Expand All @@ -42,18 +45,16 @@ List<String> getJobFolders() {
}

void seedJob(String dslFileName) {
final String LOOKUP_STRATEGY = 'SEED_JOB' // 'JENKINS_ROOT'

catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
jobDsl targets: dslFileName,
lookupStrategy: LOOKUP_STRATEGY,
lookupStrategy: getLookupStrategy(),
ignoreExisting: false,
ignoreMissingFiles: true,
removedJobAction: 'DISABLE',
removedConfigFilesAction: 'IGNORE',
removedViewAction: 'DELETE',
unstableOnDeprecation: true,
//additionalClasspath: 'src/main/groovy',
additionalClasspath: 'src',
additionalParameters: [
WORKSPACE: env.WORKSPACE,
DSL_ROOT : env.WORKSPACE,
Expand All @@ -62,14 +63,17 @@ void seedJob(String dslFileName) {
}

void seedFolder(String folder) {
final String LOOKUP_STRATEGY = 'SEED_JOB' // 'JENKINS_ROOT'

catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
jobDsl lookupStrategy: LOOKUP_STRATEGY,
jobDsl scriptText: folderDslScript(folder),
lookupStrategy: getLookupStrategy(),
removedJobAction: 'DISABLE',
removedConfigFilesAction: 'DELETE',
removedViewAction: 'DELETE',
scriptText: folderDslScript(folder)
additionalClasspath: 'src',
additionalParameters: [
WORKSPACE: env.WORKSPACE,
DSL_ROOT : env.WORKSPACE,
]
}
}

Expand All @@ -82,3 +86,10 @@ String folderDslScript(String folder) {"""
String getJobsPrefix() {
'jobs/'
}

String getLookupStrategy() {
if (LookupStrategy.values().any { params.LOOKUP_STRATEGY == it.name() }) {
return params.LOOKUP_STRATEGY
}
'SEED_JOB'
}
10 changes: 10 additions & 0 deletions jobs/Admin/seed/Jenkinsfile.dsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
pipelineJob 'Admin/seed', {
parameters {
choiceParam {
name 'LOOKUP_STRATEGY'
description 'Describes how relative path to jobs are processed: relative to the Seed job or Jenkins root'
choices ['SEED_JOB', 'JENKINS_ROOT']
}
}
properties {
disableConcurrentBuilds()
}
definition {
cpsScm {
scm {
Expand Down

0 comments on commit af257f2

Please sign in to comment.