summaryrefslogtreecommitdiff
path: root/jenkins
diff options
context:
space:
mode:
authorArseney300 <Arseney300@gmail.com>2026-02-20 23:01:21 +0700
committerArseney300 <Arseney300@gmail.com>2026-02-20 23:01:21 +0700
commit96e6bed785911d317fa206578b08eba1baa06ad3 (patch)
tree2a16733381d2744b0cc18fc6b1f4d29248d32ee3 /jenkins
parentfc6afe6c6181fcee7741a4a15edf2a6d55185b7d (diff)
Add pipeline durability fix and stuck build cleanup script
Mount jenkins/init.groovy.d/ into the container to auto-clean corrupted flow executions on startup (JENKINS-50407). Document both the prevention (Performance-optimized durability setting) and recovery (groovy cleanup script) in the setup guide. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'jenkins')
-rw-r--r--jenkins/docker-compose.yaml1
-rw-r--r--jenkins/init.groovy.d/clear-stuck-builds.groovy37
2 files changed, 38 insertions, 0 deletions
diff --git a/jenkins/docker-compose.yaml b/jenkins/docker-compose.yaml
index 843980b..fbbe3c7 100644
--- a/jenkins/docker-compose.yaml
+++ b/jenkins/docker-compose.yaml
@@ -12,6 +12,7 @@ services:
volumes:
- /var/jenkins_home:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
+ - ./init.groovy.d:/var/jenkins_home/init.groovy.d:ro
networks:
jenkins_network:
ipv4_address: 172.23.0.2
diff --git a/jenkins/init.groovy.d/clear-stuck-builds.groovy b/jenkins/init.groovy.d/clear-stuck-builds.groovy
new file mode 100644
index 0000000..0b3a6b7
--- /dev/null
+++ b/jenkins/init.groovy.d/clear-stuck-builds.groovy
@@ -0,0 +1,37 @@
+// clear-stuck-builds.groovy
+//
+// This script runs automatically every time Jenkins starts.
+// It cleans up corrupted/stuck pipeline flow executions that can occur
+// when a build is interrupted uncleanly (timeout, abort, crash, etc.).
+//
+// Without this, Jenkins can enter a state where new pipeline builds
+// silently fail — they show "Started by user ..." and nothing else.
+// The Jenkins log will contain warnings like:
+//
+// WARNING o.j.p.w.f.FlowExecutionList$DefaultStorage#unregister:
+// <job>#<build> was not in the list to begin with: []
+//
+// This is a known Jenkins bug: https://issues.jenkins.io/browse/JENKINS-50407
+//
+// The fix: on startup, iterate through all registered flow executions
+// and remove any that are already complete but still tracked, preventing
+// them from blocking future builds.
+
+import org.jenkinsci.plugins.workflow.flow.FlowExecutionList
+
+println "[clear-stuck-builds] Checking for stuck flow executions..."
+
+int cleaned = 0
+FlowExecutionList.get().each { exec ->
+ if (exec.isComplete()) {
+ println "[clear-stuck-builds] Cleaning up completed execution: ${exec}"
+ FlowExecutionList.get().unregister(exec.owner)
+ cleaned++
+ }
+}
+
+if (cleaned > 0) {
+ println "[clear-stuck-builds] Cleaned up ${cleaned} stuck execution(s)"
+} else {
+ println "[clear-stuck-builds] No stuck executions found"
+}