简体   繁体   English

我可以在共享库中定义和参数化整个声明性管道吗?

[英]Can I have an entire declarative pipeline defined and parameterized in a shared library?

Essentially I want my Jenkinsfile to look something like this:基本上我希望我的 Jenkinsfile 看起来像这样:

@Library('my-descriptive-pipline') _
myPipeline('arg1','arg2','arg3')

Then my shared library (/vars/descriptivePipeline.groovy) would look like this:然后我的共享库 (/vars/descriptivePipeline.groovy) 将如下所示:

pipeline {
    agent any
    options {
      skipDefaultCheckout()
    }
    environment {
    }
    stages {
        stage('stageA') {
            steps {
                ... Do something with arg1, arg2 or arg3
            }
        }
        stage('stageB') {
            steps {
                ... Do something with arg1, arg2 or arg3
            }
        }
    ....

I want to centralize the pipeline config so I don't have to worry about Jenkinsfile sprawl.我想集中管道配置,所以我不必担心 Jenkinsfile 蔓延。 Is this possible with declarative pipelines?声明式管道可以做到这一点吗?

Entire Pipelines can now be defined in shared libraries as of Declarative Pipeline 1.2.从声明式管道 1.2 开始,现在可以在共享库中定义整个管道。

You can find more here and here你可以在这里这里找到更多

As the shared libraries plugin documentation states:正如共享库插件文档所述:

Defining Declarative Pipelines定义声明式管道

Starting with Declarative 1.2, released in late September, 2017, you can define Declarative Pipelines in your shared libraries as well.从 2017 年 9 月下旬发布的声明式 1.2 开始,您也可以在共享库中定义声明式管道。

This is fairly new and so there might still be a few bugs around but it should work.这是相当新的,因此可能仍然存在一些错误,但它应该可以工作。 Don't forget to upgrade the shared library and declarative plugins though.不要忘记升级共享库和声明性插件。

No, it is not currently possible to share a complete declarative pipeline.不,目前无法共享完整的声明性管道。 It is possible with scripted pipelines:使用脚本化管道可能的:

Begin quote: "The declarative option is nice but you will lose the ability to extract out reusable code via the shared library. For example, you can't do this yet:开始引用:“声明性选项很好,但你将失去通过共享库提取可重用代码的能力。例如,你还不能这样做:

MyCompanyStandardPipeline {
    ... // which will plugin standard sections...
}

End quote from Cuong Tran on the jenkins users mailing list .jenkins 用户邮件列表上结束来自 Cuong Tran 的引用。

You can use shared libraries with either Jenkinsfile variant, as the next reply on the linked thread points out, but only with scripted can you share a complete pipeline.您可以将共享库与 Jenkinsfile 变体一起使用,正如链接线程上的下一个回复所指出的那样,但只有使用脚本才能共享完整的管道。

不建议在共享库中拥有整个管道......因为开发人员永远不会知道幕后发生了什么......声明性的Entrie目标将消失......我建议创建一个可重用的类或脚本并让开发人员组成管道

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

相关问题 声明式管道共享库 - Declarative Pipeline shared library 如何在继承自管道共享库的声明性 jenkins 管道中定义其他参数? - How can I define additional parameters in a declarative jenkins pipeline who inherit from a pipeline shared library? 我可以为脚本式管道到声明式方法中的方法创建共享库.groovy脚本吗 - Can i create a shared library .groovy script for a method in scripted pipeline into declarative 我可以将声明性管道的整个阶段包装为groovy库函数吗? - Can I wrap a whole stage of a declarative pipeline as groovy library function? Jenkins 声明式管道使用共享库配置代理 - Jenkins declarative pipeline configuring the agent using shared library 为什么此声明式管道在我的共享库中失败? - Why does this declarative pipeline fail in my shared library? Jenkins 声明性管道 - 从共享库设置路径 - Jenkins Declarative Pipeline - Set PATH from shared library 如何将可变参数默认值传递给共享的声明性 jenkins 管道? - How can I pass variable parameter defaults to a shared declarative jenkins pipeline? 我可以“导入”Jenkins 声明式管道中的阶段吗 - Can I “import” the stages in a Jenkins Declarative pipeline 在 Jenkins 管道中使用共享库时,我是否必须在共享库中使用“call{}”? - Do i have to use "call{}" in a shared library when using it in a Jenkins pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM