From 8958427a6e81c260039c4fa80e3fea0de9923fff Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 17:24:08 -0500 Subject: [PATCH 01/16] Add buildCause() --- vars/buildCause.groovy | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 vars/buildCause.groovy diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy new file mode 100644 index 0000000..efcdd4e --- /dev/null +++ b/vars/buildCause.groovy @@ -0,0 +1,20 @@ +// vars/buildCause.groovy + +/** + * Return the reason for the build + */ +def call(Map config = [:]) { + + String buildUser = "Unknown" + String buildCauses = currentBuild.rawBuild.getCauses() + echo buildCauses + if (buildCauses.contains("hudson.triggers.TimerTrigger")){ + buildUser = "TimerTrigger" + } else { + wrap([$class: 'BuildUser']) { + buildUser = "${BUILD_USER}" + } + } + echo "Initiated by: ${buildUser}" + +} From b1cd444f2582f762c84f48a9d2e00ec464f6a583 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 18:12:33 -0500 Subject: [PATCH 02/16] Don't really care about the user --- vars/buildCause.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index efcdd4e..0d056ac 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -10,11 +10,11 @@ def call(Map config = [:]) { echo buildCauses if (buildCauses.contains("hudson.triggers.TimerTrigger")){ buildUser = "TimerTrigger" - } else { + } /* jelse { wrap([$class: 'BuildUser']) { buildUser = "${BUILD_USER}" } - } + }*/ echo "Initiated by: ${buildUser}" } From 49c61a47f9b93a982f0dab16423fe341d0cc56c8 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 18:55:41 -0500 Subject: [PATCH 03/16] Debug --- vars/buildCause.groovy | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 0d056ac..8be8930 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -3,11 +3,16 @@ /** * Return the reason for the build */ -def call(Map config = [:]) { +Boolean call(Map config = [:]) { String buildUser = "Unknown" String buildCauses = currentBuild.rawBuild.getCauses() echo buildCauses + echo buildCauses.getShortDescription() + echo buildCauses.getUserId() + echo buildCauses.getUserName() + echo buildCauses.getUserUrl() + echo buildCauses.hashCode() if (buildCauses.contains("hudson.triggers.TimerTrigger")){ buildUser = "TimerTrigger" } /* jelse { @@ -17,4 +22,5 @@ def call(Map config = [:]) { }*/ echo "Initiated by: ${buildUser}" + return buildUser == "TimerTrigger" } From 71c3788d35da4512e9da9da73dfb5a221ea65331 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 19:02:08 -0500 Subject: [PATCH 04/16] Fix type --- vars/buildCause.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 8be8930..4a49c36 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -6,7 +6,7 @@ Boolean call(Map config = [:]) { String buildUser = "Unknown" - String buildCauses = currentBuild.rawBuild.getCauses() + def buildCauses = currentBuild.rawBuild.getCauses() echo buildCauses echo buildCauses.getShortDescription() echo buildCauses.getUserId() From bfea7c41016fc870f6a82f2512d5cfddb3e70a9e Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 19:07:41 -0500 Subject: [PATCH 05/16] Update # NOTE: The following default set of pragmas will result in no build # or test. # # Please edit the list of pragmas to produce the minimal amount of build # and test to prove your PR works. # # Or if you have already done the above, and your PR is ready for it's # final for-landing run, remove all of the following pragmas. # # More detail can be found at # https://wiki.hpdd.intel.com/display/CI/Commit+Pragmas. --- vars/buildCause.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 4a49c36..616c7dc 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -7,7 +7,7 @@ Boolean call(Map config = [:]) { String buildUser = "Unknown" def buildCauses = currentBuild.rawBuild.getCauses() - echo buildCauses + //echo buildCauses echo buildCauses.getShortDescription() echo buildCauses.getUserId() echo buildCauses.getUserName() From 454b86e0284123b8cd45007fbb7d4f8ae2042fcc Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 19:17:32 -0500 Subject: [PATCH 06/16] And for something completely different --- vars/buildCause.groovy | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 616c7dc..8c91326 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -6,6 +6,9 @@ Boolean call(Map config = [:]) { String buildUser = "Unknown" + println "CAUSE ${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause).properties}" + + /* def buildCauses = currentBuild.rawBuild.getCauses() //echo buildCauses echo buildCauses.getShortDescription() @@ -15,6 +18,7 @@ Boolean call(Map config = [:]) { echo buildCauses.hashCode() if (buildCauses.contains("hudson.triggers.TimerTrigger")){ buildUser = "TimerTrigger" + */ } /* jelse { wrap([$class: 'BuildUser']) { buildUser = "${BUILD_USER}" From be9a1ed907cf3242926ff67aa7e81a807af8648d Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 19:20:45 -0500 Subject: [PATCH 07/16] Fix syntax --- vars/buildCause.groovy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 8c91326..263dcf6 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -18,8 +18,7 @@ Boolean call(Map config = [:]) { echo buildCauses.hashCode() if (buildCauses.contains("hudson.triggers.TimerTrigger")){ buildUser = "TimerTrigger" - */ - } /* jelse { + }*/ /* else { wrap([$class: 'BuildUser']) { buildUser = "${BUILD_USER}" } From 81a514836c61f6c29d9d36ed41ff19f862c17977 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 19:29:31 -0500 Subject: [PATCH 08/16] Something else --- vars/buildCause.groovy | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 263dcf6..2c593a2 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -7,6 +7,13 @@ Boolean call(Map config = [:]) { String buildUser = "Unknown" println "CAUSE ${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause).properties}" + //[userName:Brian J. Murrell, userIdOrUnknown:bmurrell, userId:bmurrell, class:class hudson.model.Cause$UserIdCause, userUrl:user/bmurrell, shortDescription:Started by user Brian J. Murrell] + def causes = currentBuild.getBuildCauses() + + // Get a specific Cause type (in this case the user who kicked off the build), + // if present. + def specificCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause') + print "specificCause: " + specificCause /* def buildCauses = currentBuild.rawBuild.getCauses() From f3c8fd9517a9af12ac8421cc11ab13283cee8742 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 19:37:28 -0500 Subject: [PATCH 09/16] More --- vars/buildCause.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 2c593a2..025a6cd 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -13,7 +13,9 @@ Boolean call(Map config = [:]) { // Get a specific Cause type (in this case the user who kicked off the build), // if present. def specificCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause') - print "specificCause: " + specificCause + println "specificCause: " + specificCause + + println currentBuild.getBuildCauses().shortDescription[0] /* def buildCauses = currentBuild.rawBuild.getCauses() From 9c1256dac76ee5a58b5806af817d6ca17cee6d65 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 19:47:13 -0500 Subject: [PATCH 10/16] Updates --- vars/buildCause.groovy | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 025a6cd..2b8873e 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -7,7 +7,13 @@ Boolean call(Map config = [:]) { String buildUser = "Unknown" println "CAUSE ${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause).properties}" - //[userName:Brian J. Murrell, userIdOrUnknown:bmurrell, userId:bmurrell, class:class hudson.model.Cause$UserIdCause, userUrl:user/bmurrell, shortDescription:Started by user Brian J. Murrell] + /* [userName:Brian J. Murrell, + userIdOrUnknown:bmurrell, + userId:bmurrell, + class:class hudson.model.Cause$UserIdCause, + userUrl:user/bmurrell, + shortDescription:Started by user Brian J. Murrell] + */ def causes = currentBuild.getBuildCauses() // Get a specific Cause type (in this case the user who kicked off the build), @@ -17,6 +23,7 @@ Boolean call(Map config = [:]) { println currentBuild.getBuildCauses().shortDescription[0] + /* def buildCauses = currentBuild.rawBuild.getCauses() //echo buildCauses @@ -34,5 +41,5 @@ Boolean call(Map config = [:]) { }*/ echo "Initiated by: ${buildUser}" - return buildUser == "TimerTrigger" + return !currentBuild.getBuildCauses('hudson.triggers.TimerTrigger$TimerTriggerCause').isEmpty() } From 60ed50f00cdc634e47faebe7653b58e360dd14d3 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 20:02:12 -0500 Subject: [PATCH 11/16] Handle null --- vars/buildCause.groovy | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 2b8873e..23b210d 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -6,7 +6,11 @@ Boolean call(Map config = [:]) { String buildUser = "Unknown" - println "CAUSE ${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause).properties}" + if (${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)) { + println "CAUSE ${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause).properties}" + } else { + println "currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) is null" + } /* [userName:Brian J. Murrell, userIdOrUnknown:bmurrell, userId:bmurrell, From 4d092b0429d39487197ce2bd6124cab86260aed1 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 20:06:18 -0500 Subject: [PATCH 12/16] Fix syntax --- vars/buildCause.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 23b210d..7559095 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -6,7 +6,7 @@ Boolean call(Map config = [:]) { String buildUser = "Unknown" - if (${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)) { + if (${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause}) { println "CAUSE ${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause).properties}" } else { println "currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) is null" From d3744dd3ef3005137e2b3d9868bafbd5257b07d1 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 20:11:10 -0500 Subject: [PATCH 13/16] Fix syntax again --- vars/buildCause.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 7559095..0ebf9b9 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -6,7 +6,7 @@ Boolean call(Map config = [:]) { String buildUser = "Unknown" - if (${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause}) { + if (${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)}) { println "CAUSE ${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause).properties}" } else { println "currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) is null" From 210142a16c3ec1b96fdfec87d9139c612d051d38 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 20:16:48 -0500 Subject: [PATCH 14/16] It's not in a string --- vars/buildCause.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index 0ebf9b9..e387074 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -6,7 +6,7 @@ Boolean call(Map config = [:]) { String buildUser = "Unknown" - if (${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)}) { + if (currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)) { println "CAUSE ${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause).properties}" } else { println "currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) is null" From 742ff0dd98805f13ac8afb7a01cf15be3d7e86a8 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 20:25:56 -0500 Subject: [PATCH 15/16] Summore --- vars/buildCause.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vars/buildCause.groovy b/vars/buildCause.groovy index e387074..7360d7a 100644 --- a/vars/buildCause.groovy +++ b/vars/buildCause.groovy @@ -9,7 +9,9 @@ Boolean call(Map config = [:]) { if (currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)) { println "CAUSE ${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause).properties}" } else { - println "currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) is null" + println "currentBuild.rawBuild.getCause(hudson.model.Cause\$UserIdCause) is null" + println "so, " + currentBuild.rawBuild.getCause(hudson.triggers.TimerTrigger$TimerTriggerCause) + println "and " + currentBuild.getBuildCauses('hudson.triggers.TimerTrigger$TimerTriggerCause').isEmpty() } /* [userName:Brian J. Murrell, userIdOrUnknown:bmurrell, From 9631bb64d9def2f4b5b3b4f3de30d86366672d52 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 9 Dec 2020 20:42:49 -0500 Subject: [PATCH 16/16] Add startedByTimer() --- vars/startedByTimer.groovy | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 vars/startedByTimer.groovy diff --git a/vars/startedByTimer.groovy b/vars/startedByTimer.groovy new file mode 100644 index 0000000..1a93439 --- /dev/null +++ b/vars/startedByTimer.groovy @@ -0,0 +1,13 @@ +// vars/startedByTimer.groovy + +/** + * Return the reason for the build + * + * This needs to be here rather than in pipeline-lib or Jenkinsfile due to + * Scripts not permitted to use method net.sf.json.JSON isEmpty. + */ +Boolean call(Map config = [:]) { + + return !currentBuild.getBuildCauses('hudson.triggers.TimerTrigger$TimerTriggerCause').isEmpty() + +}