Jenkins 脚本化管道或声明性管道 [英] Jenkins scripted pipeline or declarative pipeline

查看:31
本文介绍了Jenkins 脚本化管道或声明性管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的旧式项目基础工作流转换为基于 Jenkins 的管道.在浏览 docs 时,我发现有两种不同的语法,名为 scripted声明性.例如最近(2016 年底)发布的 Jenkins web declarative 语法.虽然有一个新的语法版本 Jenkins 仍然支持脚本语法.

I'm trying to convert my old style project base workflow to a pipeline based on Jenkins. While going through docs I found there are two different syntaxes named scripted and declarative. Such as the Jenkins web declarative syntax release recently (end of 2016). Although there is a new syntax release Jenkins still supports scripted syntax as well.

现在,我不确定这两种类型在哪种情况下最合适.那么 declarative 会成为 Jenkins 管道的未来吗?

Now, I'm not sure in which situation each of these two types would be a best match. So will declarative be the future of the Jenkins pipeline?

任何人都可以分享对这两种语法类型的一些想法.

Anyone who can share some thoughts about these two syntax types.

推荐答案

最初创建 Jenkins Pipeline 时,选择了 Groovy 作为基础.Jenkins 长期以来一直带有嵌入式 Groovy 引擎,为管理员和用户提供高级脚本功能.此外,Jenkins 流水线的实现者发现 Groovy 是构建现在称为脚本化流水线"的坚实基础.DSL.

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.

由于它是一个功能齐全的编程环境,Scripted Pipeline 为 Jenkins 用户提供了极大的灵活性和可扩展性.Groovy 学习曲线通常并不适合给定团队的所有成员,因此创建声明式流水线是为了为创作 Jenkins 流水线提供更简单、更自以为是的语法.

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.

两者在本质上都是相同的流水线子系统.它们都是管道即代码"的持久实现.它们都能够使用内置于 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

它们的不同之处在于语法和灵活性.声明式以更严格和预定义的结构限制用户可用的内容,使其成为更简单的持续交付管道的理想选择.Scripted 提供的限制很少,因为结构和语法的唯一限制往往由 Groovy 本身定义,而不是任何特定于 Pipeline 的系统,使其成为高级用户和具有更复杂需求的用户的理想选择.顾名思义,Declarative Pipeline 鼓励声明式编程模型.而脚本式流水线遵循更命令式的编程模型.

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.

复制自语法比较

这篇关于Jenkins 脚本化管道或声明性管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆