Jenkins Pipeline include stages in a body

45 views Asked by At

I would like to create a shared library with common steps but just one stage in different for instance build maven and build npm.

And I'm imaging it like this

def pipe(Map args, Closure body) {
    node {
        stage('some stage 1'){
            println "do something"
        }
        stage('some common stage 2'){
            println "do something else"
        }
        stage("build"){
          body(args)
        }
    }
}
def maven(Map args){
    pipe(args){ $ -> (Map _args){
            println _args
            sh "mvn package clean"
    }
}

def npm(Map args){
    pipe(args){ $ -> (Map _args){
            println _args
            sh "npm"
    }
}

It's working, but I have some concerns, it doesn't look beautiful, how could I reach my goal might be more beautiful way? What do you think?

0

There are 0 answers