简体   繁体   中英

Custom initialization steps in Jenkins Shared Library

There's a Jenkins Shared Library containing a declarative pipeline definition which I intend to use in my project. It's available in this form:

// vars/sharedLibrary.groovy

def call(Map config = [:]) {
   pipeline {
       stages {
           // ...
       }
   }
}

I'm not the owner of the library code and don't really want (or can) change or fork it.

Now, using the library in my project would look like this:

// Jenkinsfile

sharedLibrary param1: 'value', param2: 'values'

The problem is that I need to execute a few custom initialization steps before sharedLibrary is run. I'm struggling to implement it since sharedLibrary declares the "full" pipeline with the pipeline {} block, not allowing me to inject any custom logic prior to that.

This is what I want (which is obviously incorrect):

// Jenkinsfile

pipeline {
    stages {
        stage('My custom initialization logic') {
            // ...
        }
    }

    // The rest of the shared logic goes here:
    sharedLibrary param1: 'value', param2: 'values'
}

What would be your advice on making this possible?

Use scrpted pipeline syntax instead.

@Library('pipeline-sample')_

node {
    echo 'Do your stuff here'
}

sharedLibrary param1: 'value', param2: 'values'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM