Refactors CI notification to use JSON payload

Updates the CI notification process to send a JSON payload to the notification service, instead of constructing the JSON string directly in the Jenkinsfile. This improves readability, maintainability, and simplifies data handling for both success and failure scenarios. It also allows for easier extension of the data being sent in the future.
This commit is contained in:
2025-10-08 19:43:58 +02:00
parent b1ba23f9c0
commit 985e4de77d

28
Jenkinsfile vendored
View File

@@ -98,25 +98,39 @@ pipeline {
if (params.BUILD_TYPE in ['Both', 'Release']) {
urlsList << "${env.BUILD_URL}artifact/builds/KhaoticEngineReborn_Release.zip"
}
// Convertir en une chaîne JSON valide d'URLs
def urlsJson = urlsList.collect { "\"${it}\"" }.join(',')
urlsJson = "[${urlsJson}]"
def data = [
userId: params.DISCORD_USER_ID,
status: 'success',
urls: urlsList
]
def jsonFile = "${env.WORKSPACE}\\payload.json"
writeFile file: jsonFile, text: groovy.json.JsonOutput.toJson(data)
bat """
curl -X POST http://192.168.1.131:2500/ci-notify ^
-H "Content-Type: application/json" ^
-d "{\\"userId\\":\\"${params.DISCORD_USER_ID}\\",\\"status\\":\\"success\\",\\"urls\\":${urlsJson}}"
-H "Content-Type: application/json" ^
--data @${jsonFile}
"""
}
}
failure {
script {
def data = [
userId: params.DISCORD_USER_ID,
status: 'failure',
urls: []
]
def jsonFile = "${env.WORKSPACE}\\payload-fail.json"
writeFile file: jsonFile, text: groovy.json.JsonOutput.toJson(data)
bat """
curl -X POST http://192.168.1.131:2500/ci-notify ^
-H "Content-Type: application/json" ^
-d "{\\"userId\\":\\"${params.DISCORD_USER_ID}\\",\\"status\\":\\"failure\\",\\"urls\\":[]}"
-H "Content-Type: application/json" ^
--data @${jsonFile}
"""
}
}
}
}