简体   繁体   English

Jenkins共享库中的自定义初始化步骤

[英]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.有一个 Jenkins 共享库,其中包含我打算在我的项目中使用的声明性管道定义。 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.问题是我需要在运行sharedLibrary之前执行一些自定义初始化步骤。 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.我正在努力实现它,因为sharedLibrary使用pipeline {}块声明“完整”管道,不允许我在此之前注入任何自定义逻辑。

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.请改用 scrpted 管道语法。

@Library('pipeline-sample')_

node {
    echo 'Do your stuff here'
}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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