Maybe this is already possible, but at the moment I have no idea how to define reusable stages in a shared library - any hint would be very much appreciated. I would also be willing to provide a PR, if only I had an idea which code to touch

share build stages across similar projects, to keep things DRY and have a central shared library defining the various build stages per project types.

i.e.: I might have many many microservices all using the same 1) package restore 2) lint 3) build 4) run unit tests stages with only parameter differences and it would be awesome if app devs can just include a single line with the necessary parameters to call these 4 steps.

CJ Harmath
added a comment - 2019-06-07 19:27 - edited I would like this as well.
Use case:
share build stages across similar projects, to keep things DRY and have a central shared library defining the various build stages per project types.
i.e.: I might have many many microservices all using the same 1) package restore 2) lint 3) build 4) run unit tests stages with only parameter differences and it would be awesome if app devs can just include a single line with the necessary parameters to call these 4 steps.
so instead of
stages {
stage( 'restore' ) {
steps {
echo ' package restore'
restore()
}
}
stage( 'build' ) {
steps {
echo 'building'
build()
}
}
stage( 'test' ) {
steps {
echo 'testing'
test()
}
}
}
you could do this:
stages {
sharedMicroserviceStages()
}

CJ Harmath
added a comment - 2019-06-07 19:36 Okay, so I just re-read the docs and as I understand what I should be doing is to just put the entire pipeline into my shared library.
https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-declarative-pipelines
This kind of makes me wonder if we allow defining entire pipeline, why not allow stages as well ?
But I guess I am already happy with this as I only need to maintain one pipeline per app type.

Dan Alvizu
added a comment - 2019-08-09 21:11 For anyone else who runs into this: Andrew closed this as 'FIxed but unreleased' but with a resolution of 'Duplicate'.
The duplicate issue is JENKINS-49135 and track there