From 58445410317ce4ad9c0961f81e6b0c03039fc2dc Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Wed, 30 Aug 2023 11:11:21 -0600 Subject: [PATCH] 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 --- Jenkinsfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 87ccd4a..65b396d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,6 +58,9 @@ pipeline { stages { stage('Prepare') { steps { + setBuildStatus("pending", "Pending") + slackSend(color: "good", message: "${env.JOB_NAME} - #${env.BUILD_ID} started (<${env.BUILD_URL}|Open>)") + checkout([ $class: 'GitSCM', branches: [[name: "${GIT_BRANCH}"]], @@ -76,9 +79,6 @@ pipeline { 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 # Install dependencies #./scripts/deps.sh @@ -124,15 +124,15 @@ pipeline { } success { 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 { 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 { 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>)") } } }