Is it possible to insert stages into a pipeline at run time, or build the pipeline dynamically?

I’m currently writing a bunch of pipelines for work to shutdown and startup our applications for maintenance. Currently I am doing a POC with three applications so I have 6 pipelines (start/stop app A, start/stop app B and start/stop app C). If this is successful more apps will be added to this.

However, depending on what is being maintained, we may be able to leave one or apps online, and so I’m trying to make a bunch of extra pipelines to only turn off (and then back on) the correct apps to make things a bit easier for the users. Currently I’m doing this by having the new pipelines build the necessary jobs, however my company is using dynamic pods, and so for each new build task a new pod is created which adds to the run time.

So my question is, is it possible to put the stage to stop and start each app into a library file and use that to insert the stage into my new pipelines from this library file. So rather than being:
stages {
stage(“Shutdown App A”) {
steps {
script {
build job: “Shutdown App A”
stage(“Shutdown App C”) {
steps {
script {
build job: “Shutdown App C”

It would be something like
stages {

Is something like this possible? I have only really been able to find referenced to shared libraries when googling but they seem to only allow inserting a single complete pipeline which I’ve not been able to work with.

Thank you