From 985e4de77d8bf4adf9ebf6962208066db55c863d Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Wed, 8 Oct 2025 19:43:58 +0200 Subject: [PATCH] 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. --- Jenkinsfile | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5f604a9..7d3de5d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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} """ } } } + } \ No newline at end of file