-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
592c99c
commit 4afa43a
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
withNode { | ||
stage('checkout') { | ||
checkout scm | ||
} | ||
stage('seed') { | ||
getJobFolders().each { | ||
seedFolder it | ||
} | ||
getDslFiles().each { | ||
seedJob it | ||
} | ||
} | ||
} | ||
|
||
void withNode(Closure body) { | ||
Closure wrappedBody = { -> ansiColor 'xterm', body } | ||
if (env.NODE_LABEL) { | ||
node env.NODE_LABEL, wrappedBody | ||
} | ||
else { | ||
node wrappedBody | ||
} | ||
} | ||
|
||
List<String> getDslFiles() { | ||
findFiles(glob: 'jobs/**/Jenkinsfile.dsl') | ||
.findAll { !it.directory } | ||
.collect { it.path } | ||
.toSorted() | ||
} | ||
|
||
List<String> getJobFolders() { | ||
getDslFiles() | ||
.collect { | ||
it.replaceFirst('^jobs/', '') | ||
.replaceFirst('([^/]+/)?Jenkinsfile[.]dsl$', '') | ||
.replaceFirst('/$', '') | ||
} | ||
.findAll { it != '' } | ||
.toSorted() | ||
.toUnique() | ||
} | ||
|
||
void seedJob(String dslFileName) { | ||
final String LOOKUP_STRATEGY = 'SEED_JOB' // 'JENKINS_ROOT' | ||
|
||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { | ||
jobDsl targets: dslFileName, | ||
lookupStrategy: LOOKUP_STRATEGY, | ||
ignoreExisting: false, | ||
ignoreMissingFiles: true, | ||
removedJobAction: 'DISABLE', | ||
removedConfigFilesAction: 'IGNORE', | ||
removedViewAction: 'DELETE', | ||
unstableOnDeprecation: true, | ||
//additionalClasspath: 'src/main/groovy', | ||
additionalParameters: [ | ||
WORKSPACE: env.WORKSPACE, | ||
DSL_ROOT : env.WORKSPACE, | ||
] | ||
} | ||
} | ||
|
||
void seedFolder(String folder) { | ||
final String LOOKUP_STRATEGY = 'SEED_JOB' // 'JENKINS_ROOT' | ||
|
||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { | ||
jobDsl lookupStrategy: LOOKUP_STRATEGY, | ||
removedJobAction: 'DISABLE', | ||
removedConfigFilesAction: 'DELETE', | ||
removedViewAction: 'DELETE', | ||
scriptText: folderDslScript(folder) | ||
} | ||
} | ||
|
||
String folderDslScript(String folder) {""" | ||
folder '$folder', { | ||
displayName '$folder 🔹' | ||
} | ||
"""} | ||
|
||
String getJobsPrefix() { | ||
'jobs/' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pipelineJob 'Admin/seed', { | ||
definition { | ||
cpsScm { | ||
scm { | ||
github 'turboBasic/JenkinsLibrary', 'main' | ||
} | ||
scriptPath jenkinsFileName('Admin/seed') | ||
} | ||
} | ||
} | ||
|
||
String jenkinsFileName(String jobName) { | ||
"jobs/$jobName/Jenkinsfile" | ||
} |