This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch refactor
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit c63f29846a8dfa36a58672e899ae8566622e42ab
Author: tqchen <[email protected]>
AuthorDate: Sat Feb 15 10:14:27 2025 -0500

    Update jenkins to only rerun in last build
---
 ci/jenkins/generated/arm_jenkinsfile.groovy     |  89 ++++++++++----
 ci/jenkins/generated/cpu_jenkinsfile.groovy     | 105 +++++++++++-----
 ci/jenkins/generated/docker_jenkinsfile.groovy  |   9 +-
 ci/jenkins/generated/gpu_jenkinsfile.groovy     |  73 +++++++----
 ci/jenkins/generated/hexagon_jenkinsfile.groovy | 153 +++++++++++++++++-------
 ci/jenkins/generated/i386_jenkinsfile.groovy    |  73 +++++++----
 ci/jenkins/generated/lint_jenkinsfile.groovy    |   9 +-
 ci/jenkins/generated/wasm_jenkinsfile.groovy    |  25 +++-
 ci/jenkins/templates/utils/Prepare.groovy.j2    |   7 ++
 ci/jenkins/templates/utils/macros.j2            |  32 +++--
 10 files changed, 412 insertions(+), 163 deletions(-)

diff --git a/ci/jenkins/generated/arm_jenkinsfile.groovy 
b/ci/jenkins/generated/arm_jenkinsfile.groovy
index a8949af697..5e48cc6500 100644
--- a/ci/jenkins/generated/arm_jenkinsfile.groovy
+++ b/ci/jenkins/generated/arm_jenkinsfile.groovy
@@ -60,7 +60,7 @@
 // 'python3 jenkins/generate.py'
 // Note: This timestamp is here to ensure that updates to the Jenkinsfile are
 // always rebased on main before merging:
-// Generated at 2025-02-14T17:21:20.745906
+// Generated at 2025-02-15T10:14:10.162250
 
 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
 // These are set at runtime from data in ci/jenkins/docker-images.yml, update
@@ -279,6 +279,13 @@ def cancel_previous_build() {
   }
 }
 
+def is_last_build() {
+  // whether it is last build
+  def job = Jenkins.instance.getItem(env.JOB_NAME)
+  def lastBuild = job.getLastBuild()
+  return lastBuild.getNumber() == env.BUILD_NUMBER
+}
+
 def checkout_trusted_files() {
   // trust everything from branch builds
   if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
@@ -523,11 +530,17 @@ def build() {
     try {
         run_build('ARM-GRAVITON3-SPOT')
     } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        run_build('ARM-GRAVITON3')
+        if (is_last_build()) {
+          // retry if we are currently at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          run_build('ARM-GRAVITON3')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
     }
   }
 }
@@ -735,44 +748,68 @@ def test() {
       try {
       shard_run_integration_aarch64_1_of_4('ARM-GRAVITON3-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_integration_aarch64_1_of_4('ARM-GRAVITON3')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_integration_aarch64_1_of_4('ARM-GRAVITON3')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'integration: aarch64 2 of 4': {
       try {
       shard_run_integration_aarch64_2_of_4('ARM-GRAVITON3-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_integration_aarch64_2_of_4('ARM-GRAVITON3')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_integration_aarch64_2_of_4('ARM-GRAVITON3')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'integration: aarch64 3 of 4': {
       try {
       shard_run_integration_aarch64_3_of_4('ARM-GRAVITON3-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_integration_aarch64_3_of_4('ARM-GRAVITON3')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_integration_aarch64_3_of_4('ARM-GRAVITON3')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'integration: aarch64 4 of 4': {
       try {
       shard_run_integration_aarch64_4_of_4('ARM-GRAVITON3-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_integration_aarch64_4_of_4('ARM-GRAVITON3')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_integration_aarch64_4_of_4('ARM-GRAVITON3')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     )
diff --git a/ci/jenkins/generated/cpu_jenkinsfile.groovy 
b/ci/jenkins/generated/cpu_jenkinsfile.groovy
index 647ded7f26..b54fdf51ca 100644
--- a/ci/jenkins/generated/cpu_jenkinsfile.groovy
+++ b/ci/jenkins/generated/cpu_jenkinsfile.groovy
@@ -60,7 +60,7 @@
 // 'python3 jenkins/generate.py'
 // Note: This timestamp is here to ensure that updates to the Jenkinsfile are
 // always rebased on main before merging:
-// Generated at 2025-02-09T12:21:01.787826
+// Generated at 2025-02-15T10:14:10.181874
 
 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
 // These are set at runtime from data in ci/jenkins/docker-images.yml, update
@@ -279,6 +279,13 @@ def cancel_previous_build() {
   }
 }
 
+def is_last_build() {
+  // whether it is last build
+  def job = Jenkins.instance.getItem(env.JOB_NAME)
+  def lastBuild = job.getLastBuild()
+  return lastBuild.getNumber() == env.BUILD_NUMBER
+}
+
 def checkout_trusted_files() {
   // trust everything from branch builds
   if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
@@ -528,11 +535,17 @@ def build() {
     try {
         run_build('CPU-SPOT')
     } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        run_build('CPU')
+        if (is_last_build()) {
+          // retry if we are currently at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          run_build('CPU')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
     }
   }
 }
@@ -781,55 +794,85 @@ def test() {
       try {
       shard_run_integration_CPU_1_of_4('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_integration_CPU_1_of_4('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_integration_CPU_1_of_4('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'integration: CPU 2 of 4': {
       try {
       shard_run_integration_CPU_2_of_4('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_integration_CPU_2_of_4('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_integration_CPU_2_of_4('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'integration: CPU 3 of 4': {
       try {
       shard_run_integration_CPU_3_of_4('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_integration_CPU_3_of_4('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_integration_CPU_3_of_4('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'integration: CPU 4 of 4': {
       try {
       shard_run_integration_CPU_4_of_4('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_integration_CPU_4_of_4('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_integration_CPU_4_of_4('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'unittest: CPU 1 of 1': {
       try {
       shard_run_unittest_CPU_1_of_1('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_unittest_CPU_1_of_1('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_unittest_CPU_1_of_1('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     )
diff --git a/ci/jenkins/generated/docker_jenkinsfile.groovy 
b/ci/jenkins/generated/docker_jenkinsfile.groovy
index b7947ab2bf..daad2188ff 100644
--- a/ci/jenkins/generated/docker_jenkinsfile.groovy
+++ b/ci/jenkins/generated/docker_jenkinsfile.groovy
@@ -60,7 +60,7 @@
 // 'python3 jenkins/generate.py'
 // Note: This timestamp is here to ensure that updates to the Jenkinsfile are
 // always rebased on main before merging:
-// Generated at 2025-02-09T12:21:01.715947
+// Generated at 2025-02-15T10:12:52.000152
 
 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
 // These are set at runtime from data in ci/jenkins/docker-images.yml, update
@@ -279,6 +279,13 @@ def cancel_previous_build() {
   }
 }
 
+def is_last_build() {
+  // whether it is last build
+  def job = Jenkins.instance.getItem(env.JOB_NAME)
+  def lastBuild = job.getLastBuild()
+  return lastBuild.getNumber() == env.BUILD_NUMBER
+}
+
 def checkout_trusted_files() {
   // trust everything from branch builds
   if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
diff --git a/ci/jenkins/generated/gpu_jenkinsfile.groovy 
b/ci/jenkins/generated/gpu_jenkinsfile.groovy
index 3d3f3175c3..236447bdc2 100644
--- a/ci/jenkins/generated/gpu_jenkinsfile.groovy
+++ b/ci/jenkins/generated/gpu_jenkinsfile.groovy
@@ -60,7 +60,7 @@
 // 'python3 jenkins/generate.py'
 // Note: This timestamp is here to ensure that updates to the Jenkinsfile are
 // always rebased on main before merging:
-// Generated at 2025-02-15T09:43:05.709342
+// Generated at 2025-02-15T10:14:10.120180
 
 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
 // These are set at runtime from data in ci/jenkins/docker-images.yml, update
@@ -279,6 +279,13 @@ def cancel_previous_build() {
   }
 }
 
+def is_last_build() {
+  // whether it is last build
+  def job = Jenkins.instance.getItem(env.JOB_NAME)
+  def lastBuild = job.getLastBuild()
+  return lastBuild.getNumber() == env.BUILD_NUMBER
+}
+
 def checkout_trusted_files() {
   // trust everything from branch builds
   if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
@@ -529,11 +536,17 @@ def build() {
     try {
         run_build('CPU-SPOT')
     } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        run_build('CPU')
+        if (is_last_build()) {
+          // retry if we are currently at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          run_build('CPU')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
     }
   }
 }
@@ -703,33 +716,51 @@ def test() {
       try {
       shard_run_unittest_GPU_1_of_2('GPU-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_unittest_GPU_1_of_2('GPU')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_unittest_GPU_1_of_2('GPU')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'unittest: GPU 2 of 2': {
       try {
       shard_run_unittest_GPU_2_of_2('GPU-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_unittest_GPU_2_of_2('GPU')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_unittest_GPU_2_of_2('GPU')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'docs: GPU 1 of 1': {
       try {
       shard_run_docs_GPU_1_of_1('GPU-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_docs_GPU_1_of_1('GPU')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_docs_GPU_1_of_1('GPU')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     )
diff --git a/ci/jenkins/generated/hexagon_jenkinsfile.groovy 
b/ci/jenkins/generated/hexagon_jenkinsfile.groovy
index 0155a7a843..da20f33bbb 100644
--- a/ci/jenkins/generated/hexagon_jenkinsfile.groovy
+++ b/ci/jenkins/generated/hexagon_jenkinsfile.groovy
@@ -60,7 +60,7 @@
 // 'python3 jenkins/generate.py'
 // Note: This timestamp is here to ensure that updates to the Jenkinsfile are
 // always rebased on main before merging:
-// Generated at 2025-02-09T12:21:01.760323
+// Generated at 2025-02-15T10:14:10.056677
 
 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
 // These are set at runtime from data in ci/jenkins/docker-images.yml, update
@@ -279,6 +279,13 @@ def cancel_previous_build() {
   }
 }
 
+def is_last_build() {
+  // whether it is last build
+  def job = Jenkins.instance.getItem(env.JOB_NAME)
+  def lastBuild = job.getLastBuild()
+  return lastBuild.getNumber() == env.BUILD_NUMBER
+}
+
 def checkout_trusted_files() {
   // trust everything from branch builds
   if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
@@ -527,11 +534,17 @@ def build() {
     try {
         run_build('CPU-SPOT')
     } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        run_build('CPU')
+        if (is_last_build()) {
+          // retry if we are currently at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          run_build('CPU')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
     }
   }
 }
@@ -920,88 +933,136 @@ def test() {
       try {
       shard_run_test_Hexagon_1_of_8('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_test_Hexagon_1_of_8('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_test_Hexagon_1_of_8('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'test: Hexagon 2 of 8': {
       try {
       shard_run_test_Hexagon_2_of_8('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_test_Hexagon_2_of_8('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_test_Hexagon_2_of_8('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'test: Hexagon 3 of 8': {
       try {
       shard_run_test_Hexagon_3_of_8('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_test_Hexagon_3_of_8('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_test_Hexagon_3_of_8('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'test: Hexagon 4 of 8': {
       try {
       shard_run_test_Hexagon_4_of_8('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_test_Hexagon_4_of_8('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_test_Hexagon_4_of_8('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'test: Hexagon 5 of 8': {
       try {
       shard_run_test_Hexagon_5_of_8('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_test_Hexagon_5_of_8('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_test_Hexagon_5_of_8('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'test: Hexagon 6 of 8': {
       try {
       shard_run_test_Hexagon_6_of_8('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_test_Hexagon_6_of_8('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_test_Hexagon_6_of_8('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'test: Hexagon 7 of 8': {
       try {
       shard_run_test_Hexagon_7_of_8('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_test_Hexagon_7_of_8('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_test_Hexagon_7_of_8('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'test: Hexagon 8 of 8': {
       try {
       shard_run_test_Hexagon_8_of_8('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_test_Hexagon_8_of_8('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_test_Hexagon_8_of_8('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     )
diff --git a/ci/jenkins/generated/i386_jenkinsfile.groovy 
b/ci/jenkins/generated/i386_jenkinsfile.groovy
index 5651091936..993f1d3e83 100644
--- a/ci/jenkins/generated/i386_jenkinsfile.groovy
+++ b/ci/jenkins/generated/i386_jenkinsfile.groovy
@@ -60,7 +60,7 @@
 // 'python3 jenkins/generate.py'
 // Note: This timestamp is here to ensure that updates to the Jenkinsfile are
 // always rebased on main before merging:
-// Generated at 2025-02-09T12:21:01.734278
+// Generated at 2025-02-15T10:14:10.142167
 
 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
 // These are set at runtime from data in ci/jenkins/docker-images.yml, update
@@ -279,6 +279,13 @@ def cancel_previous_build() {
   }
 }
 
+def is_last_build() {
+  // whether it is last build
+  def job = Jenkins.instance.getItem(env.JOB_NAME)
+  def lastBuild = job.getLastBuild()
+  return lastBuild.getNumber() == env.BUILD_NUMBER
+}
+
 def checkout_trusted_files() {
   // trust everything from branch builds
   if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
@@ -523,11 +530,17 @@ def build() {
     try {
         run_build('CPU-SPOT')
     } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        run_build('CPU')
+        if (is_last_build()) {
+          // retry if we are currently at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          run_build('CPU')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
     }
   }
 }
@@ -689,33 +702,51 @@ def test() {
       try {
       shard_run_python_i386_1_of_3('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_python_i386_1_of_3('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_python_i386_1_of_3('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'python: i386 2 of 3': {
       try {
       shard_run_python_i386_2_of_3('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_python_i386_2_of_3('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_python_i386_2_of_3('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     'python: i386 3 of 3': {
       try {
       shard_run_python_i386_3_of_3('CPU-SMALL-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        shard_run_python_i386_3_of_3('CPU-SMALL')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          shard_run_python_i386_3_of_3('CPU-SMALL')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     )
diff --git a/ci/jenkins/generated/lint_jenkinsfile.groovy 
b/ci/jenkins/generated/lint_jenkinsfile.groovy
index d85f6af857..a1750eb853 100644
--- a/ci/jenkins/generated/lint_jenkinsfile.groovy
+++ b/ci/jenkins/generated/lint_jenkinsfile.groovy
@@ -60,7 +60,7 @@
 // 'python3 jenkins/generate.py'
 // Note: This timestamp is here to ensure that updates to the Jenkinsfile are
 // always rebased on main before merging:
-// Generated at 2025-02-09T12:21:01.747933
+// Generated at 2025-02-15T10:12:51.981152
 
 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
 // These are set at runtime from data in ci/jenkins/docker-images.yml, update
@@ -279,6 +279,13 @@ def cancel_previous_build() {
   }
 }
 
+def is_last_build() {
+  // whether it is last build
+  def job = Jenkins.instance.getItem(env.JOB_NAME)
+  def lastBuild = job.getLastBuild()
+  return lastBuild.getNumber() == env.BUILD_NUMBER
+}
+
 def checkout_trusted_files() {
   // trust everything from branch builds
   if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
diff --git a/ci/jenkins/generated/wasm_jenkinsfile.groovy 
b/ci/jenkins/generated/wasm_jenkinsfile.groovy
index a0cb13d558..407f4c8004 100644
--- a/ci/jenkins/generated/wasm_jenkinsfile.groovy
+++ b/ci/jenkins/generated/wasm_jenkinsfile.groovy
@@ -60,7 +60,7 @@
 // 'python3 jenkins/generate.py'
 // Note: This timestamp is here to ensure that updates to the Jenkinsfile are
 // always rebased on main before merging:
-// Generated at 2025-02-09T12:21:01.801132
+// Generated at 2025-02-15T10:14:10.202706
 
 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
 // These are set at runtime from data in ci/jenkins/docker-images.yml, update
@@ -279,6 +279,13 @@ def cancel_previous_build() {
   }
 }
 
+def is_last_build() {
+  // whether it is last build
+  def job = Jenkins.instance.getItem(env.JOB_NAME)
+  def lastBuild = job.getLastBuild()
+  return lastBuild.getNumber() == env.BUILD_NUMBER
+}
+
 def checkout_trusted_files() {
   // trust everything from branch builds
   if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
@@ -525,11 +532,17 @@ def build() {
     try {
         run_build('CPU-SPOT')
     } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        run_build('CPU')
+        if (is_last_build()) {
+          // retry if we are currently at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          run_build('CPU')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
     }
   }
 }
diff --git a/ci/jenkins/templates/utils/Prepare.groovy.j2 
b/ci/jenkins/templates/utils/Prepare.groovy.j2
index 3f27b98861..68e6569d4e 100644
--- a/ci/jenkins/templates/utils/Prepare.groovy.j2
+++ b/ci/jenkins/templates/utils/Prepare.groovy.j2
@@ -155,6 +155,13 @@ def cancel_previous_build() {
   }
 }
 
+def is_last_build() {
+  // whether it is last build
+  def job = Jenkins.instance.getItem(env.JOB_NAME)
+  def lastBuild = job.getLastBuild()
+  return lastBuild.getNumber() == env.BUILD_NUMBER
+}
+
 def checkout_trusted_files() {
   // trust everything from branch builds
   if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
diff --git a/ci/jenkins/templates/utils/macros.j2 
b/ci/jenkins/templates/utils/macros.j2
index 81eeaa1fdf..ee90b043cc 100644
--- a/ci/jenkins/templates/utils/macros.j2
+++ b/ci/jenkins/templates/utils/macros.j2
@@ -96,11 +96,17 @@ def build() {
     try {
         run_build('{{ node }}-SPOT')
     } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        run_build('{{ node }}')
+        if (is_last_build()) {
+          // retry if we are currently at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          run_build('{{ node }}')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
     }
   }
 }
@@ -119,11 +125,17 @@ def test() {
       try {
       {{ method_name }}('{{ node }}-SPOT')
       } catch (Throwable ex) {
-        // mark the current stage as success
-        // and try again via on demand node
-        echo 'Exception during SPOT run ' + ex.toString() + ' retry on-demand'
-        currentBuild.result = 'SUCCESS'
-        {{ method_name }}('{{ node }}')
+        if (is_last_build()) {
+          // retry if at last build
+          // mark the current stage as success
+          // and try again via on demand node
+          echo 'Exception during SPOT run ' + ex.toString() + ' retry 
on-demand'
+          currentBuild.result = 'SUCCESS'
+          {{ method_name }}('{{ node }}')
+        } else {
+          echo 'Exception during SPOT run ' + ex.toString() + ' exit since it 
is not last build'
+          throw ex
+        }
       }
     },
     {% endfor %}


Reply via email to