Building a builder shared library for declarative pipelines

34 views
Skip to first unread message

Nick Stolwijk

unread,
Aug 22, 2019, 10:42:29 AM8/22/19
to jenkins...@googlegroups.com
Hello list,

We are busy converting our jobs to the Multibranch Pipeline. 

We had a lot of jobs generated by the JobDSL.
- Build develop
- Build feature branches
- Sonar builds for develop and feature branches

We configured our jobs in the same repository as our JobDSL.

For the Multibranch Pipeline, we want to create a shared library, so we can have a common ground for all our old jobs.

We based our shared library on one we found on Github [1] and called the builder as follows:

@Library('chefci') _
org.typo3.chefci.v2.cookbook.CookbookPipeline.builder(this, steps)
        .buildDefaultPipeline()
        .execute()
Then we wanted to change the stages to suit our needs and created a Maven stage:
@Override
void execute() {
script.stage(stageName) {
script.when(script.branch('feature/*'))
script.withMaven(
mavenSettingsConfig: 'e6609549-d884-4978-9750-61bdb982db2e',
publisherStrategy: 'EXPLICIT',
options: [
script.pipelineGraphPublisher(),
script.mavenLinkerPublisher(),
script.junitPublisher(healthScaleFactor: 1.0),
script.dependenciesFingerprintPublisher(),
script.artifactsPublisher()],
) {
script.sh "mvn clean --batch-mode --update-snapshots -Pintegration deploy"
}
script.chuckNorris()
}
}
This didn't work, because of the `script.when` line. 
Is it possible to have a `when` block when using this method?
Also, is this a good way to setup a shared library for the declarative pipeline? Are there anymore good examples? I find a lot of documentation, but a lot is unclear if it is for the scripted or declarative pipeline.
I hope someone can help me with this.
With regards,
Nick Stolwijk
[1] https://github.com/TYPO3-infrastructure/jenkins-pipeline-global-library-chefci

~~~ Try to leave this world a little better than you found it and, when your turn comes to die, you can die happy in feeling that at any rate you have not wasted your time but have done your best ~~~

Lord Baden-Powell
Reply all
Reply to author
Forward
0 new messages