Is there a simple and fast way to get the reasons of an error or an unstable of downstream job? And at what stage did this happen?
We have one reason of unstable that we don’t care about (we can’t change downstream job).
A little bit of an example:
pipeline {
agent { label "masterLin" }
options { timestamps() }
stages {
stage('Run'){
steps {
script {
def jobBuild = build job: 'test_2'//, propagate: false
//test_2 going unstable (by warnError method) on stage "Send info" with " ERROR: " in log
//How can i ignore it and mark my (upstream) stage as successful?
//But (!) if the downstream job is unstable or in error by any other reason then leave default marking rules (mark my upstream stage as unstable/error)
//if possible without propagate: false
}
}
}
}
I tried something like this:
String errorTime
@NonCPS
def getLine(jobBuild) {
def BUILD_STRING1 = " ERROR: "
jobBuild.getRawBuild().getLog().eachLine { line ->
if (line =~ /$BUILD_STRING1/ ) {
if (line.contains("Failed to send info")){
println line.plus(" ignoring it")
errorTime = line.substring(0, line.indexOf(' ERROR: '))
//Trying to take 2 string of that error message
//but timestamps can be different on those errors
//so it didn't work well
}
else if (line.contains(errorTime)) {
println line.plus(" ignoring it")
else { unstable(line) }
}
}
}
pipeline {
agent { label "masterLin" }
options { timestamps() }
stages {
stage('Run'){
steps {
script {
def jobBuild = build job: 'test_2', propagate: false
if (jobBuild.result == 'UNSTABLE') {
echo "UNSTABLE"
getLine(jobBuild)
} else if (jobBuild.result == 'FAILURE') {
echo "ERROR"
currentBuild.result='FAILURE'
}
}
}
}
}
post {
cleanup {
cleanWs()
}
}
}
But it works like sh..t 🙂
Example of the end of the log from the downstream job:
[Pipeline] stage
[Pipeline] { (Send info)
[Pipeline] warnError
[Pipeline] {
[Pipeline] dir
...
[2024-06-04T09:25:58.906Z] [ssh-agent] Stopped.
[Pipeline] // sshagent
[Pipeline] }
[Pipeline] // withVaultCredential
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[2024-06-04T09:25:59.198Z] ERROR: Failed to send info
[2024-06-04T09:25:59.199Z] ERROR: script returned exit code 1
[Pipeline] // warnError
[Pipeline] }
[Pipeline] // stage
[Pipeline] cleanWs
[2024-06-04T09:25:59.295Z] [WS-CLEANUP] Deleting project workspace...
[2024-06-04T09:25:59.295Z] [WS-CLEANUP] Deferred wipeout is used...
[2024-06-04T09:25:59.326Z] [WS-CLEANUP] done
[Pipeline] }
[2024-06-04T09:25:59.329Z]
[Pipeline] // ansiColor
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: UNSTABLE