我用凹槽脚本读取了一个 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
}
}
}
}
结果是:
任何人都可以帮助我显示正确的状态?谢谢!