jenkins - 詹金斯/凹槽 - 显示所有阶段失败的动态阶段
问题描述
我用凹槽脚本读取了一个 shell 脚本文件 /tmp/cmd_list.sh 并创建了一个动态阶段来构建。
/tmp/cmd_list.sh 的内容是:
ls pwd aaaaaa who
只有“aaaaaa”mut 无法执行(退出代码 127)。我的问题是,所有阶段都标记为失败,但是当我看到日志时,“ls”、“pwd”和“who”等命令工作正常,返回码为 0。
我试图关注盒子的阶段状态,但没有成功......我的 Groove 脚本(Jenkinsfile):
import hudson.model.Result
node('master') {
stage ('\u27A1 Checkout'){
sh "echo 'checkout ok'"
}
def BUILD_LIST = readFile('/tmp/cmd_list.sh').split()
for (CMDRUN in BUILD_LIST) {
def status;
try {
node{
stage(CMDRUN) {
println "Building ..."
status = sh(returnStatus: true, script: CMDRUN )
println "---> EX CODE: "+ status
if(status == 0){
currentBuild.result = 'SUCCESS'
currentBuild.rawBuild.@result = hudson.model.Result.SUCCESS
}
else{
currentBuild.result = 'UNSTABLE'
currentBuild.rawBuild.@result = hudson.model.Result.UNSTABLE
}
def e2e = build job:CMDRUN, propagate: false
}
}
}
catch (e) {
println "===> " + e
currentBuild.result = 'UNSTABLE'
println "++++> EX CODE: "+ status
if(status == 0){
println "++++> NEW STATUS: "+ status
currentBuild.rawBuild.@result = hudson.model.Result.SUCCESS
currentBuild.result = 'SUCCESS'
}
else{
println "++++> NEW STATUS: "+ status
currentBuild.rawBuild.@result = hudson.model.Result.UNSTABLE
}
}
}
}
结果是:
任何人都可以帮助我显示正确的状态?谢谢!
解决方案
我更改了脚本,现在按预期工作!
新代码:
node('master') {
def build_ok = true
stage ('\u27A1 Checkout'){
sh "echo 'checkout ok'"
}
def BUILD_LIST = readFile('/tmp/cmd_list.sh').split()
for (CMDRUN in BUILD_LIST) {
try {
stage(CMDRUN) {
println "Building ..."
sh CMDRUN
}
}
catch (e) { build_ok = false }
}
if(build_ok) { currentBuild.result = "SUCCESS" }
else { currentBuild.result = "FAILURE" }
}
推荐阅读
- python - 显示从网站上的提要中提取的随机推文的问题
- python - 使用functools LRU缓存时去除非输入参数?
- javascript - 从数组数组创建一个新数组
- docker - 在 docker 容器中创建文件(高山图像)
- git - 我可以在我的 PATH 中没有 git 的情况下使用颤振吗?
- django - 我的 django 搜索功能有问题
- android - 带有单个 WebView 的 Android Studio 简单“电视”应用程序在长时间后崩溃(分析器显示负分配的内存?)
- exception - Pyspark Dataframe:无法解决计算列的平均值/平均值/聚合(包括空值)
- python - python并行的两个连续多处理池
- html - 部分未出现在标题下方