diff --git a/Jenkinsfile b/Jenkinsfile index 45ab432..b7078db 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,6 @@ +#!/usr/bin/env groovy +library 'status-jenkins-lib@v1.8.6' + pipeline { agent { label 'linux' } @@ -108,47 +111,11 @@ pipeline { cleanup { cleanWs() } always { script { def result = currentBuild.result.toLowerCase() ?: 'unknown' - discordNotify(header: "Logos Press Engine Docker image build ${result}!") + discord.send( + header: "Logos Press Engine Docker image build ${result}!", + descPrefix: "Image: [`${env.IMAGE_NAME}:${params.IMAGE_TAG}`](https://harbor.status.im/${params.IMAGE_NAME}/tags?name=${params.IMAGE_TAG})", + cred: 'logos-press-engine-discord-webhook-url', + ) } } } } - -def discordNotify(Map args=[:]) { - def opts = [ - header: args.header ?: 'Deployment successful!', - title: args.title ?: "${env.JOB_NAME}#${env.BUILD_NUMBER}", - cred: args.cred ?: 'logos-press-engine-discord-webhook-url', - ] - 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: opts.title, - description: """ - ${opts.header} - Image: [`${env.IMAGE_NAME}:${params.IMAGE_TAG}`](https://harbor.status.im/${params.IMAGE_NAME}/tags?name=${params.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}) - """, - ) - } -}