pipeline { agent any stages { stage('Restore tlw-database-tool') { steps { copyArtifacts filter: '**/tlw-database-tool-1.0.jar', fingerprintArtifacts: true, projectName: 'build tlw-database-tool', selector: lastSuccessful(), target: '.' } } stage('Execute') { steps { script { String jdkPath = tool name: 'OpenJDK19', type: 'jdk' withCredentials([usernamePassword(credentialsId: 'aws', passwordVariable: 'AWS_SECRET_KEY', usernameVariable: 'AWS_ACCESS_KEY_ID')]) { withEnv(["JAVA_HOME=${jdkPath}/jdk-19.0.2","AWS_SECRET_KEY=${AWS_SECRET_KEY}", "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"]) { String outputBuild = "" String output = "" String errorOutput = "" String outputTemp = "" try { outputTemp = sh returnStdout: true, script: "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesUpdaterFootball --season ${season} --league 48 --configFile WTL-Pokal 2>&1" output += outputTemp } catch (Exception e) { errorOutput += outputTemp } try { outputTemp = sh returnStdout: true, script: "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchdaysUpdater --season ${season} --league 48 --configFile WTL-Pokal 2>&1" output += outputTemp } catch (Exception e) { errorOutput += outputTemp } try { outputTemp = sh returnStdout: true, script: "java -jar build/libs/tlw-database-tool-1.0.jar --mode TeamsUpdater --season ${season} --league 48 --configFile WTL-Pokal 2>&1" output += outputTemp } catch (Exception e) { errorOutput += outputTemp } if(output != "") { output = clean(output) output.split('\n').toList().unique().each { telegramSendManual(it) } } if(errorOutput != "") { ArrayList outputList = outputString.replace("\n\n", "\n").split('\n').toList() outputList = clean(outputList) outputList.each { telegramSendManual(it) } } } } } } } stage('CleanUp') { steps { deleteDir() } } } post { failure { telegramSendManual("Build failed!\n${env.BUILD_URL}console") } } } private ArrayList clean(ArrayList orig) { ArrayList cleaned = new ArrayList() orig.each{line -> if(line.indexOf(" [main] INFO de.jeyp91 - ") >= 0) { line = line.substring(20, line.size()) } if(line.indexOf(" [main] ERROR de.jeyp91") >= 0) { line = line.substring(20, line.size()) } cleaned.add(line) } return cleaned.unique() } def telegramSendManual(String text) { def encodedMessage = URLEncoder.encode(text, "UTF-8") println encodedMessage httpRequest( httpMode: 'GET', contentType: 'APPLICATION_JSON', responseHandle: 'NONE', url: "https://api.telegram.org/bot1298223079:AAEplcQpfzFG59qNYAYuSbJKtB9HMXCCE_U/sendMessage?text=$encodedMessage&chat_id=459231986&disable_web_page_preview=true", wrapAsMultipart: false, consoleLogResponseBody: true ) }