Add WhatsApp reminder

This commit is contained in:
2024-06-18 21:21:27 +02:00
parent 0d5307cf1a
commit 662850c35c
8 changed files with 422 additions and 56 deletions

View File

@@ -0,0 +1,83 @@
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', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_KEY'),
usernamePassword(credentialsId: 'forum_database', usernameVariable: 'TLW_DATABASE_USERNAME', passwordVariable: 'TLW_DATABASE_PASSWORD'),
usernamePassword(credentialsId: 'forum_user', usernameVariable: 'FORUM_USERNAME', passwordVariable: 'FORUM_PASSWORD')
secretText(credentialsId: 'WhatsApp_Token', secretVariable: 'TLW_WHATSAPP_API_KEY')
secretText(credentialsId: 'OPENAI_TOKEN', secretVariable: 'OPENAI_TOKEN')
]) {
withEnv([
"JAVA_HOME=${jdkPath}/jdk-19.0.2"
]) {
try {
sh "ls build/libs"
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode WhatsAppNotifier --season ${season} --league 1 --configFile Tippliga 2>&1 >> log.txt"
} catch (Exception e) {
telegramSendManual("TLW-Database-Tool crashed!")
}
String outputString = readFile 'log.txt'
if(outputString != "") {
ArrayList<String> 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<String> clean(ArrayList<String> orig) {
ArrayList<String> cleaned = new ArrayList<String>()
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) {
sleep 1
if(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
)
}
}