隆重推出定义 Jenkins Pipeline 的新方法
| 这是 Jenkins World 发言人 Andrew Bayer 的客座文章,他是 CloudBees 的 Jenkins 开发者。 |

在过去的几年里,代码即 Pipeline(Pipeline as code)已成为 Jenkins 的未来——事实上,在这一点上,我认为它已经非常稳固地成为了 Jenkins 的现在。但这并不意味着它已经完成,更不用说它是完美的了。虽然许多开发者喜欢通过编写脚本来使用 Pipeline 所获得的强大功能和控制力,但并非所有人都这么认为。很多开发者希望通过配置来指定他们的构建,然后继续构建软件。
Pipeline 脚本一直不是做到这一点的好方法……直到现在。
通过对 Jenkins Pipeline 的新更改,您现在可以通过安装新的 Pipeline Model Definition 插件,从 Jenkinsfile 中的配置来定义您的 Pipeline。您今天就可以通过更新中心进行尝试。请务必查看 文档,其中包含各种语言和平台的入门示例。
这是一个基于插件自己的 Jenkinsfile 的快速示例
pipeline {
// Make sure that the tools we need are installed and on the path.
tools {
maven "Maven 3.3.9"
jdk "Oracle JDK 8u40"
}
// Run on any executor.
agent label:""
// The order that sections are specified doesn't matter - this will still be run
// after the stages, even though it's specified before the stages.
postBuild {
// No matter what the build status is, run these steps. There are other conditions
// available as well, such as "success", "failed", "unstable", and "changed".
always {
archive "target/**/*"
junit 'target/surefire-reports/*.xml'
}
}
stages {
// While there's only one stage here, you can specify as many stages as you like!
stage("build") {
sh 'mvn clean install -Dmaven.test.failure.ignore=true'
}
}
}
这项功能仍处于早期阶段,还有许多进一步的功能计划使其更容易、更直观地定义您的 Pipeline。所有这些功能都建立在 Pipeline 脚本之上,因此我们将继续改进 Pipeline 步骤和模型之外的语法!也许最令人兴奋的是,Pipeline 模型将用于一个正在开发的视觉编辑器,该编辑器将成为 Blue Ocean 项目的一部分——虽然编辑器还没有准备好,但 Pipeline Model Definition 插件将与 Blue Ocean Beta 版捆绑在一起供您试用。
我将在 9 月 15 日星期四下午 3:45 的 Jenkins World 演讲中深入探讨这一切以及更多内容,并在当天午餐时间的演示剧场进行展示。我迫不及待地想在那里见到大家,并听听大家对此的看法!
|
Andrew 将于 9 月份在 Jenkins World 上 展示更多这个概念。使用代码 |