From e0bfc47032119811ca99ae6c6c1149769ffce9c8 Mon Sep 17 00:00:00 2001 From: Julian Arndt Date: Mon, 19 May 2025 22:17:12 +0200 Subject: [PATCH] Add Jenkinsfile for Relegation --- jenkinsfiles/RelegationUpdater/Jenkinsfile | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 jenkinsfiles/RelegationUpdater/Jenkinsfile diff --git a/jenkinsfiles/RelegationUpdater/Jenkinsfile b/jenkinsfiles/RelegationUpdater/Jenkinsfile new file mode 100644 index 0000000..5f0c7aa --- /dev/null +++ b/jenkinsfiles/RelegationUpdater/Jenkinsfile @@ -0,0 +1,80 @@ +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: 'OpenJDK22', type: 'jdk' + withCredentials([ + usernamePassword(credentialsId: 'aws', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_ACCESS_KEY'), + usernamePassword(credentialsId: 'forum_database', usernameVariable: 'TLW_DATABASE_USERNAME', passwordVariable: 'TLW_DATABASE_PASSWORD'), + usernamePassword(credentialsId: 'forum_user', usernameVariable: 'FORUM_USERNAME', passwordVariable: 'FORUM_PASSWORD') + ]) { + withEnv([ + "JAVA_HOME=${jdkPath}/jdk-22.0.2" + ]) { + try { + sh "$JAVA_HOME/bin/java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesUpdaterFootball --season ${season} --league 47 --configFile Relegation >> log.txt 2>&1" + sh "$JAVA_HOME/bin/java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchdaysUpdater --season ${season} --league 47 --configFile Relegation >> log.txt 2>&1" + sh "$JAVA_HOME/bin/java -jar build/libs/tlw-database-tool-1.0.jar --mode TeamsUpdater --season ${season} --league 47 --configFile Relegation >> log.txt 2>&1" + sh "$JAVA_HOME/bin/java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesResultsUpdater --season ${season} --league 47 --configFile Relegation >> log.txt 2>&1" + } catch (Exception e) { + telegramSendManual("TLW-Database-Tool crashed!") + } + String outputString = readFile 'log.txt' + if(outputString != "") { + ArrayList outputList = outputString.replace("\n\n", "\n").split('\n').toList() + outputList = clean(outputList) + outputList.each { + telegramSendManual(it) + } + } + } + } + } + } + } + } + post { + always { + deleteDir() + } + 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 + ) +} \ No newline at end of file