Jenkins 脚本化管道或声明性管道

zhujiabin 阅读:52 2025-06-02 22:19:02 评论:0

我正在尝试将我的旧式项目基础工作流转换为基于 Jenkins 的管道。在经过时docs我发现有两种不同的语法,名为 scripteddeclarative .如Jenkins网站declarative语法最近发布(2016 年底)。尽管有一个新的语法版本,Jenkins 仍然支持脚本语法。
现在,我不确定这两种类型在哪种情况下是最佳匹配。 declarative也是如此成为 Jenkins 管道的 future ?
任何可以分享有关这两种语法类型的想法的人。

请您参考如下方法:

When Jenkins Pipeline was first created, Groovy was selected as the foundation. Jenkins has long shipped with an embedded Groovy engine to provide advanced scripting capabilities for admins and users alike. Additionally, the implementors of Jenkins Pipeline found Groovy to be a solid foundation upon which to build what is now referred to as the "Scripted Pipeline" DSL.

As it is a fully featured programming environment, Scripted Pipeline offers a tremendous amount of flexibility and extensibility to Jenkins users. The Groovy learning-curve isn’t typically desirable for all members of a given team, so Declarative Pipeline was created to offer a simpler and more opinionated syntax for authoring Jenkins Pipeline.

The two are both fundamentally the same Pipeline sub-system underneath. They are both durable implementations of "Pipeline as code." They are both able to use steps built into Pipeline or provided by plugins. Both are able to utilize Shared Libraries

Where they differ however is in syntax and flexibility. Declarative limits what is available to the user with a more strict and pre-defined structure, making it an ideal choice for simpler continuous delivery pipelines. Scripted provides very few limits, insofar that the only limits on structure and syntax tend to be defined by Groovy itself, rather than any Pipeline-specific systems, making it an ideal choice for power-users and those with more complex requirements. As the name implies, Declarative Pipeline encourages a declarative programming model. Whereas Scripted Pipelines follow a more imperative programming model.


复制自 https://jenkins.io/doc/book/pipeline/syntax/#compare


标签:Jenkins
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号