Sharing steps between declarative pipelines

Hey all,

I have a declarative pipeline on a multibranch pipeline in Jenkins 2.440.3. This pipeline is responsible for checkout some related repositories, compile the source code and then run an external testing tool, reporting the results to our Teams installation.

Now I need to create something similar, up to the “compile” part, but doing something different (also, not a multibranch pipeline, and not automatically triggered by changes in the source), and I want to have the similar steps in a shared… thing (library?), that doesn’t need to be compiled or installed.

Basically, I’d like to have

Jenkins.common.

stage('outside docker') {
    stages {
        stage('Inside machine stage 1') {
            ...
        }

        stage('Inside machine stage 2') {
            ...
        }
    }
}

stage('Inside docker') {
    agent {
        ...
    }

    stages {
        stage('Clone related repo') {
            ...
        }

        stage('Set up compilation') {
            ...
        }

        stage('Build') {
            ...
        }
    }
}

And then have two pipelines with something like:

Jenkins.build

include 'Jenkins.common'

stage('Continuing from common...') {
    stages {
        stage('Tests') {
            ...
        }
    }
}

Jenkins.update:

include 'Jenkins.common'

stage('Continuing from common...') {
    stages {
        stage('Update reference values') {
            ...
        }
    }
}

The references I found on the internet said that something like this can be done in scripted pipelines. Is there a way to do something like this with Declarative pipelines?