Ida*_*dar 7 jenkins jenkins-pipeline
在声明性管道中,使用多分支作业和Jenkins文件,是否可以使用退出代码而不是退出代码中止作业?successfailure
在下面的阶段,我基本上检查启动作业的提交是否包含"ci skip",如果是,我想中止该作业.
使用error中止作业但也标记它(红色行).我希望这份工作标有绿色的行.
stage ("Checkout SCM") {
steps {
script {
checkout scm
result = sh (script: "git log -1 | grep '.*\\[ci skip\\].*'", returnStatus: true)
if (result == 0) {
error ("'ci skip' spotted in git commit. Aborting.")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:
而不是上面,我现在试图简单地跳过所有阶段,以防git提交包含"ci skip".我的理解是,如果结果expression是false,它应该跳过这个阶段......
pipeline {
environment {
shouldBuild = "true"
}
...
...
stage ("Checkout SCM") {
steps {
script {
checkout scm
result = sh (script: "git log -1 | grep '.*\\[ci skip\\].*'", returnStatus: true)
if (result == 0) {
echo ("'ci skip' spotted in git commit. Aborting.")
shouldBuild = "false"
}
}
}
}
stage ("Unit tests") {
when {
expression {
return shouldBuild
}
}
steps {
...
}
}
...
...
}
Run Code Online (Sandbox Code Playgroud)
好的,所以让它工作的方法不是使用environment指令,而是使用parameters指令。
也就是说,parameters在 的顶部添加pipeline:
parameters {
booleanParam(defaultValue: true, description: 'Execute pipeline?', name: 'shouldBuild')
}
Run Code Online (Sandbox Code Playgroud)
检查 git commit 时,如果它包含“ci skip”,我将更改以下值shouldBuild:
env.shouldBuild = "false"
Run Code Online (Sandbox Code Playgroud)
然后在expression:
expression {
return env.shouldBuild != "false"
}
Run Code Online (Sandbox Code Playgroud)
就是这样。如果 git commit 包含“ci skip”,则跳过阶段并且作业以SUCCESS.
| 归档时间: |
|
| 查看次数: |
4616 次 |
| 最近记录: |