From caeb09102bcfed248689a0aafc8948cb480edbd7 Mon Sep 17 00:00:00 2001
From: Till Wegmüller <toasterson@gmail.com>
Date: Sun, 22 Oct 2023 16:32:42 +0200
Subject: [PATCH] Try getting the hash from a famous gist example

---
 ci/user-build.groovy |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/ci/user-build.groovy b/ci/user-build.groovy
index 6d4d541..f65f1fb 100644
--- a/ci/user-build.groovy
+++ b/ci/user-build.groovy
@@ -2,6 +2,15 @@
 
 @Library("BuildLib") _
 
+/**
+ * Gets the commit hash from a Jenkins build object, if any
+ */
+@NonCPS
+def commitHashForBuild( build ) {
+  def scmAction = build?.actions.find { action -> action instanceof jenkins.scm.api.SCMRevisionAction }
+  return scmAction?.revision?.hash
+}
+
 pipeline {
     agent {
         node {
@@ -34,7 +43,8 @@
             steps {
                 withPublisher('openindiana.org', 'incremental') {
                     script {
-                        def last_commit = Jenkins.instance.getItem('OpenIndiana').getItem('Userland').lastSuccessfulBuild.changeset[0].revision
+                        def last_build = Jenkins.instance.getItem('OpenIndiana').getItem('Userland').lastSuccessfulBuild
+                        def last_commit = commitHashForBuild(last_build)
                     }
                     sh './tools/jenkinshelper-main.ksh -s build_changed $last_commit'
                 }

--
Gitblit v1.9.3