Hey!
I'm trying to set up a builder pattern that allows other developers in my team to easily set up pipeline jobs without having to know the exact groovy syntax for their jobs.
First, to clarify what I mean, I want to quickly show you how we used that for our freestyle jobs:
protected final Job job
FreeStyleJobBuilder(final DslFactory dslFactory, final String jobName) {
this.job = dslFactory.job(jobName)
}
After setting the Job object we could keep adding functions to it, for example:
FreeStyleJobBuilder addPreBuildCleanup() {
job.wrappers { preBuildCleanup() }
this
}
FreeStyleJobBuilder addHtmlReport(String htmlDirectory, String htmlFiles, String htmlReportName) {
job.publishers {
publishHtml {
report(htmlDirectory) {
reportFiles htmlFiles
reportName htmlReportName
keepAll()
alwaysLinkToLastBuild()
}
}
}
this
}
That way each developer/tester could easily set up their own job:
new FreeStyleJobBuilder(dslFactory, jobName)
.setDescription("description...")
.setLogRotator(365, 50, 365, 10)
.addPreBuildCleanup()
.setSlaveLabel(Executor.SMOKE)
.addUpstreamProjectTrigger("../TestTrigger-Smoke")
.addArtifactsToCopy("../../Build_Tester")
Now, I'm trying to set up a similar way for pipeline jobs that would enable building custom pipeline jobs with custom stages.
I know I can use "dslFactory.pipelineJob(jobName)" to get some of the pipeline features but its scope seems pretty limited and focuses on getting the pipeline script either as a script or path. I'd especially like to get the nice features from declarative pipelines while avoiding using a harcoded pipeline script.
Does anyone have any suggestions how to approach this problem?
Thanks!
Sharon