就Groovy而言,什么是Jenkins舞台? [英] What is a Jenkins Stage in terms of Groovy?
问题描述
我正试图弄清楚Grooy语法的阶段.那是什么语法:
I'm trying to figure out what is a stage in terms of Grooy syntax. What is that syntax:
stage 'stage 1'
statement 1
statement 2
statement n
stage 'stage 2'
statement 1
statement 2
statement n
还是我认为这是创建舞台的较新方法?
or I think this is the newer way to create a stage?
stage ('stage'){
statement 1
statement 2
statement n
}
第一个代码块看起来几乎像带标签的语句,但在此之后缺少冒号名字.
The first code block almost looks like labeled statements but it's missing the colon after the name.
如果我想在Groovy中做这样的事情,我该怎么做?
If I wanted to do something like this in Groovy, how would I do it?
我是詹金斯和Groovy菜鸟.
I'm a Jenkins and Groovy noob.
[试图澄清我的问题]
我想知道在Groovy代码方面什么是阶段构造.
[Attempt to clarify my question]
I wanted to know what a stage construct is in terms of Groovy code.
例如,如果我问这个Groovy代码块是什么
For example, if I asked what is this block of Groovy code
def somefnc(){
..statements
}
有人会说:这就是您在Groovy中定义函数的方法,使用关键字def
为函数命名..."
Someone would say "That is how you define a function in Groovy, you use the keyword def
give the function a name..."
我的问题是什么
stage ('stage'){
statement 1
statement 2
statement n
}
这是Groovy语言的一部分吗?这叫什么?我的理解是,Jenkins文件是Groovy代码.那么,是否有一些Jenkins预处理程序正在运行?还是上面的有效Groovy是我可以在我的普通Groovy中使用它的方式?我的意思不是"stage
",我可以定义什么并拥有一个
Is this part of the Groovy language? What is it called? My understanding is that a Jenkins file is Groovy code. So is there some Jenkins preprocessor running? Or is the above valid Groovy and I can use it some how in my plain Groovy? I don't mean "stage
", can I define whatever that is and have a
steve('some arguments'){
statments...
}
推荐答案
第二个示例是几乎正确的语法,但缺少steps{}-block
.官方 Jenkins文档对语法和其他问题有很大帮助.
Your second example is the almost correct syntax but missing a steps{}-block
. The official Jenkins documentation is a great help regarding syntaxes and other questions.
因此,对于您的示例,如果要在声明性管道中使用阶段,则这将是100%正确的语法(我认为这是您所说的较新的方式",旧方式"将是脚本化的管道) ).
So regarding your example this would be the 100% correct syntax if you want to use a stage in a declarative pipeline (I think this is what you referd as 'newer way', the 'old way' would be a scripted pipeline).
stage ('stage'){
steps {
statement 1
statement 2
statement n
}
}
这篇关于就Groovy而言,什么是Jenkins舞台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!