diff --git a/Jenkinsfile b/Jenkinsfile index b89d6fb657..9acbbeeca2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,6 +12,14 @@ def show_node_info() { """ } +// Error patterns to scan build logs for specific failure types and send detailed notifications. +def failurePatterns = [ + [pattern: /login attempt to .* failed with status: 401 Unauthorized/, description: "Docker registry authentication failed"], + [pattern: /docker login failed/, description: "Docker login failed"], + [pattern: /HTTP request sent .* 404 Not Found/, description: "HTTP request failed with 404"], + [pattern: /cat: .* No such file or directory/, description: "GPU not found"], +] + class Version { int major, minor, patch @Override @@ -1849,4 +1857,36 @@ pipeline { } } } + post { + failure { + node(rocmnode("nogpu")) { + script { + // Get the build log. + def buildLog = sh(script: 'wget -q --no-check-certificate -O - ' + BUILD_URL + 'consoleText', returnStdout: true) + // Check for patterns in the log. + def foundPatterns = [] + for (patternMap in failurePatterns) { + def result = checkForPattern(patternMap.pattern, buildLog) + if (result.found) { + foundPatterns.add([ + description: patternMap.description, + matchedLine: result.matchedLine, + context: result.context + ]) + } + } + // Send a notification for each matched failure pattern. + for (patternMap in foundPatterns) { + withCredentials([string(credentialsId: 'ck_ci_errors_webhook_url', variable: 'WEBHOOK_URL')]) { + sh ''' + curl -X POST "${WEBHOOK_URL}" \ + -H 'Content-Type: application/json' \ + -d '{"text": "\\n\\n**Build Failed**\\n\\n**Issues detected:** ''' + patternMap.description + '''\\n\\n**Log context:**\\n```\\n''' + patternMap.context.replace("'", "\\'") + '''\\n```\\n\\n**Job:** ''' + env.JOB_NAME + '''\\n\\n**Build:** #''' + env.BUILD_NUMBER + '''\\n\\n**URL:** ''' + env.RUN_DISPLAY_URL + '''"}' + ''' + } + } + } + } + } + } }