詹金斯问题 - 将帖子部分添加到基于脚本的&方法之间的区别
我有2个有关Jenkins
1的问题。两种方法之间有什么区别?
方法1
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
方法2,
node ("jenkins-nodes") {
stage("git clone"){
echo 'Hello World' }
}
- 我在第一个方法中了解到,我可以添加 post 部分,无论工作的结果如何。我希望为第二种方法添加相同的帖子部分,但它不起作用。有什么想法吗?
I have 2 questions regarding jenkins
1. What is the difference between the 2 methods?
Method 1
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
Method 2
node ("jenkins-nodes") {
stage("git clone"){
echo 'Hello World' }
}
- As I understand in the first method I can add Post section that will be running regardless of the result of the job. I wish to add the same post section for the second method, but it is not working. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AS noam helmer 写道,
pipeline {}
is 声明语法 andtax和andnode {}}
is scripteded 语法。通常,我建议始终使用
pipeline {}
,因为它使使用蓝色海洋插件更易于编写和可视化的通用任务在声明管道中最有效。当声明管道变得过于不舒服时,您可以使用
script {}
在声明管道中插入脚本块:清洁方法是定义一个函数,该函数是按定义脚本的,并将其用作自定义逐步宣布管道。请注意,即使没有
脚本{}
!在使用大量自定义代码的复杂管道中,我通常每个阶段具有一个功能。这样可以使
管道{}
清洁,并可以轻松查看管道的整体结构,而没有script {}
整个地方混乱。post {}
仅在声明管道中可用,但不在声明管道的脚本管道或脚本段中。您可以使用尝试{} catch {}最后{}
而不是。捕获{}
仅在发生错误时运行,最后{}
总是运行。您可以同时使用catch {}
和最后{}
。As Noam Helmer wrote,
pipeline{}
is declarative syntax and andnode{}
is scripted syntax.In general I recommend to always use
pipeline{}
as it makes common tasks easier to write and visualization using Blue Ocean plugin works best with declarative pipeline.When declarative pipeline becomes too unflexible, you can insert scripted blocks using the
script{}
step in a declarative pipeline:A cleaner approach is to define a function, which is scripted by definition and use that as a custom step in declarative pipeline. Note this works even without
script{}
!In complex pipelines that use lots of custom code, I usually have one function per stage. This keeps the
pipeline{}
clean and makes it easy to see the overall structure of the pipeline, withoutscript{}
clutter all over the place.post{}
is only available in declarative pipeline, but not within a scripted pipeline or a scripted section of a declarative pipeline. You can usetry{} catch{} finally{}
instead.catch{}
runs only when an error occurs,finally{}
always runs. You can use both or either ofcatch{}
andfinally{}
.