From cb1d2024588d7b287dfe6bb6b5825e0a2b26776e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Tue, 26 Sep 2023 12:08:07 +0200 Subject: [PATCH] ci: extract discordNotify to separate file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- ci/Jenkinsfile.release | 42 ++---------------------------------------- ci/discord.groovy | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 40 deletions(-) create mode 100644 ci/discord.groovy diff --git a/ci/Jenkinsfile.release b/ci/Jenkinsfile.release index 59cceb50f..d298badaf 100644 --- a/ci/Jenkinsfile.release +++ b/ci/Jenkinsfile.release @@ -81,7 +81,8 @@ pipeline { } // stages post { success { script { - discordNotify( + def discord = load 'ci/discord.groovy' + discord.notify( header: 'Nim-Waku deployment successful!', cred: 'discord-waku-deployments-webhook', ) @@ -89,42 +90,3 @@ pipeline { always { sh 'docker image prune -f' } } // post } // pipeline - -def discordNotify(Map args=[:]) { - def opts = [ - header: args.header ?: 'Deployment successful!', - cred: args.cred ?: null, - ] - def repo = [ - url: GIT_URL.minus('.git'), - branch: GIT_BRANCH.minus('origin/'), - commit: GIT_COMMIT.take(8), - prev: ( - env.GIT_PREVIOUS_SUCCESSFUL_COMMIT ?: env.GIT_PREVIOUS_COMMIT ?: 'master' - ).take(8), - ] - wrap([$class: 'BuildUser']) { - BUILD_USER_ID = env.BUILD_USER_ID - } - withCredentials([ - string( - credentialsId: opts.cred, - variable: 'DISCORD_WEBHOOK', - ), - ]) { - discordSend( - link: env.BUILD_URL, - result: currentBuild.currentResult, - webhookURL: env.DISCORD_WEBHOOK, - title: "${env.JOB_NAME}#${env.BUILD_NUMBER}", - description: """ - ${opts.header} - Image: [`${IMAGE_NAME}:${IMAGE_TAG}`](https://hub.docker.com/r/${IMAGE_NAME}/tags?name=${IMAGE_TAG}) - Branch: [`${repo.branch}`](${repo.url}/commits/${repo.branch}) - Commit: [`${repo.commit}`](${repo.url}/commit/${repo.commit}) - Diff: [`${repo.prev}...${repo.commit}`](${repo.url}/compare/${repo.prev}...${repo.commit}) - By: [`${BUILD_USER_ID}`](${repo.url}/commits?author=${BUILD_USER_ID}) - """, - ) - } -} diff --git a/ci/discord.groovy b/ci/discord.groovy new file mode 100644 index 000000000..f55ddaefc --- /dev/null +++ b/ci/discord.groovy @@ -0,0 +1,40 @@ +def discordNotify(Map args=[:]) { + def opts = [ + header: args.header ?: 'Deployment successful!', + cred: args.cred ?: null, + ] + def repo = [ + url: GIT_URL.minus('.git'), + branch: GIT_BRANCH.minus('origin/'), + commit: GIT_COMMIT.take(8), + prev: ( + env.GIT_PREVIOUS_SUCCESSFUL_COMMIT ?: env.GIT_PREVIOUS_COMMIT ?: 'master' + ).take(8), + ] + wrap([$class: 'BuildUser']) { + BUILD_USER_ID = env.BUILD_USER_ID + } + withCredentials([ + string( + credentialsId: opts.cred, + variable: 'DISCORD_WEBHOOK', + ), + ]) { + discordSend( + link: env.BUILD_URL, + result: currentBuild.currentResult, + webhookURL: env.DISCORD_WEBHOOK, + title: "${env.JOB_NAME}#${env.BUILD_NUMBER}", + description: """ + ${opts.header} + Image: [`${IMAGE_NAME}:${IMAGE_TAG}`](https://hub.docker.com/r/${IMAGE_NAME}/tags?name=${IMAGE_TAG}) + Branch: [`${repo.branch}`](${repo.url}/commits/${repo.branch}) + Commit: [`${repo.commit}`](${repo.url}/commit/${repo.commit}) + Diff: [`${repo.prev}...${repo.commit}`](${repo.url}/compare/${repo.prev}...${repo.commit}) + By: [`${BUILD_USER_ID}`](${repo.url}/commits?author=${BUILD_USER_ID}) + """, + ) + } +} + +return this