From 0d5dd25db51b01486933a5f1299ccac26521d89d Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Fri, 19 Apr 2024 10:03:47 -0700 Subject: [PATCH] jenkins: simplify timer check (#32254) simplify timer check --- Jenkinsfile | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1a0e2c73e9..efba905c6b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,26 +9,9 @@ def retryWithDelay(int maxRetries, int delay, Closure body) { throw Exception("Failed after ${maxRetries} retries") } -// check if started by timer: https://stackoverflow.com/questions/43516025/how-to-handle-nightly-build-in-jenkins-declarative-pipeline -@NonCPS +// check if started by timer: https://gist.github.com/aaclarker/75b8a0eb2b4d600779f84f8e849f2c37 def isJobStartedByTimer() { - def startedByTimer = false - try { - def buildCauses = currentBuild.rawBuild.getCauses() - for ( buildCause in buildCauses ) { - if (buildCause != null) { - def causeDescription = buildCause.getShortDescription() - echo "shortDescription: ${causeDescription}" - if (causeDescription.contains("Started by timer")) { - startedByTimer = true - } - } - } - } catch(theError) { - echo "Error getting build cause" - } - - return startedByTimer + return currentBuild.getBuildCauses()[0]["shortDescription"].matches("Started by timer"); } def device(String ip, String step_label, String cmd) {