chore(ci): reuse discord send function from library

Provides more info and requires less boilerplate.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2024-02-14 16:46:15 +01:00
parent 3f2905817a
commit bafc6dfb1f
No known key found for this signature in database
GPG Key ID: FE65CD384D5BF7B4
3 changed files with 22 additions and 55 deletions

View File

@ -1,3 +1,6 @@
#!/usr/bin/env groovy
library 'status-jenkins-lib@v1.8.6'
pipeline { pipeline {
agent { agent {
dockerfile { dockerfile {
@ -43,16 +46,16 @@ pipeline {
} }
post { post {
failure { always {
script { script {
def discord = load "${WORKSPACE}/ci/discord.groovy" discord.send(
discord.sendMessage(header: 'Nightly Fuzztest Failed. Regression files archived as job artifacts') header: (
} currentBuild.currentResult == 'SUCCESS' ?
} 'Nightly Fuzztest Passed' :
success { 'Nightly Fuzztest Failed. Regression files archived as job artifacts'
script { ),
def discord = load "${WORKSPACE}/ci/discord.groovy" cred: 'nomos-node-discord-commits-webhook',
discord.sendMessage(header: 'Nightly Fuzztest Passed') )
} }
} }
cleanup { cleanWs() } cleanup { cleanWs() }

View File

@ -1,3 +1,6 @@
#!/usr/bin/env groovy
library 'status-jenkins-lib@v1.8.6'
pipeline { pipeline {
agent { agent {
dockerfile { dockerfile {
@ -67,20 +70,13 @@ pipeline {
} }
post { post {
failure { always { script {
script { def report = readFile("${WORKSPACE}/report.txt").trim()
def report = readFile("${WORKSPACE}/report.txt").trim() discord.send(
def discord = load "${WORKSPACE}/ci/discord.groovy" header: "Nightly Integration Tests ${currentBuild.currentResult}: ${report}",
discord.sendMessage(header: "Nightly Integration Tests Failed: ${report}") cred: 'nomos-node-discord-commits-webhook',
} )
} } }
success {
script {
def report = readFile('report.txt').trim()
def discord = load "${WORKSPACE}/ci/discord.groovy"
discord.sendMessage(header: "Nightly Integration Tests Passed: ${report}")
}
}
cleanup { cleanWs() } cleanup { cleanWs() }
} }
} }

View File

@ -1,32 +0,0 @@
def sendMessage(Map args=[:]) {
def opts = [
header: args.header ?: 'Build succeeded',
title: args.title ?: "${env.JOB_NAME}#${env.BUILD_NUMBER}",
cred: args.cred ?: 'nomos-node-discord-commits-webhook',
]
def repo = [
url: GIT_URL.minus('.git'),
branch: GIT_BRANCH.minus('origin/'),
commit: GIT_COMMIT.take(8),
]
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}
Branch: [`${repo.branch}`](${repo.url}/commits/${repo.branch})
Commit: [`${repo.commit}`](${repo.url}/commit/${repo.commit})
""",
)
}
}
return this