当一个文件包含“错误”时,我需要使一个詹金斯管道阶段失败 我不知道如何从bash向Jenkins返回错误
stage('check if file continas error and exit if true') {
steps {
sh "grep 'error' filetocheck.txt"
}
}
}
答案 0 :(得分:0)
参考Is it possible to capture the stdout from the sh DSL command in the pipeline
这对我有用,
def runShell(String command){
def responseCode = sh returnStatus: true, script: "${command} &> tmp.txt"
def output = readFile(file: "tmp.txt")
return (output != "")
}
pipeline {
agent any
stages {
stage('check shellcheck') {
steps {
script {
if (runShell('grep \'error\' file_to_parse.txt')) {
sh "exit 1"
}
}
}
}
}
}