jenkins: Add build duration to Slack notifications

The scripted projects using the default Slack notifications settings
report the time the build took. Add it to the declarative jobs as well.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2023-08-30 11:11:21 -06:00
committed by Tim Crawford
parent 81731199f2
commit 5844541031

12
Jenkinsfile vendored
View File

@@ -58,6 +58,9 @@ pipeline {
stages { stages {
stage('Prepare') { stage('Prepare') {
steps { steps {
setBuildStatus("pending", "Pending")
slackSend(color: "good", message: "${env.JOB_NAME} - #${env.BUILD_ID} started (<${env.BUILD_URL}|Open>)")
checkout([ checkout([
$class: 'GitSCM', $class: 'GitSCM',
branches: [[name: "${GIT_BRANCH}"]], branches: [[name: "${GIT_BRANCH}"]],
@@ -76,9 +79,6 @@ pipeline {
userRemoteConfigs: [[url: 'https://github.com/system76/firmware-open']] userRemoteConfigs: [[url: 'https://github.com/system76/firmware-open']]
]) ])
setBuildStatus("pending", "Pending")
slackSend(color: "good", message: "${JOB_NAME} - #${BUILD_ID} started (<${BUILD_URL}|Open>)")
sh """#!/bin/bash sh """#!/bin/bash
# Install dependencies # Install dependencies
#./scripts/deps.sh #./scripts/deps.sh
@@ -124,15 +124,15 @@ pipeline {
} }
success { success {
setBuildStatus("success", "Successful") setBuildStatus("success", "Successful")
slackSend(color: "good", message: "${JOB_NAME} - #${BUILD_ID} successful (<${BUILD_URL}|Open>)") slackSend(color: "good", message: "${env.JOB_NAME} - #${env.BUILD_ID} successful after ${currentBuild.durationString} (<${env.BUILD_URL}|Open>)")
} }
failure { failure {
setBuildStatus("failure", "Failed") setBuildStatus("failure", "Failed")
slackSend(color: "danger", message: "${JOB_NAME} - #${BUILD_ID} failed (<${BUILD_URL}|Open>)") slackSend(color: "danger", message: "${env.JOB_NAME} - #${env.BUILD_ID} failed after ${currentBuild.durationString} (<${env.BUILD_URL}|Open>)")
} }
aborted { aborted {
setBuildStatus("failure", "Failed") setBuildStatus("failure", "Failed")
slackSend(color: "warning", message: "${JOB_NAME} - #${BUILD_ID} aborted (<${BUILD_URL}|Open>)") slackSend(color: "warning", message: "${env.JOB_NAME} - #${env.BUILD_ID} aborted after ${currentBuild.durationString} (<${env.BUILD_URL}|Open>)")
} }
} }
} }