David Caro has uploaded a new change for review.

Change subject: Adding the possibility to skip jobs or nodes
......................................................................

Adding the possibility to skip jobs or nodes

Change-Id: I41ed694285a6b0f7a5c57b92fcffd1cc09bd98e9
Signed-off-by: David Caro <[email protected]>
---
M jobs/confs/groovy-scripts/cleanup_workspaces.groovy
M jobs/confs/yaml/jobs/system/system_cleanup-workspaces.yaml
2 files changed, 79 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/jenkins refs/changes/65/37565/1

diff --git a/jobs/confs/groovy-scripts/cleanup_workspaces.groovy 
b/jobs/confs/groovy-scripts/cleanup_workspaces.groovy
index f0cf835..f6cb03b 100644
--- a/jobs/confs/groovy-scripts/cleanup_workspaces.groovy
+++ b/jobs/confs/groovy-scripts/cleanup_workspaces.groovy
@@ -6,6 +6,7 @@
 import hudson.FilePath.FileCallable;
 import hudson.slaves.OfflineCause;
 import hudson.node_monitors.*;
+import hudson.model.queue.Executables;
 
 
 def runOnSlave(node, cmd, workspace='/tmp') {
@@ -46,12 +47,25 @@
 
 
 curJobURL = build.getEnvironment(listener)['BUILD_URL']
+jobSkipList = build.getEnvironment(listener)['SKIP_JOBS']
+jobSkipList = jobSkipList.replace(',', ' ').split(' ')
+nodeSkipList = build.getEnvironment(listener)['SKIP_NODES']
+nodeSkipList = nodeSkipList.replace(',', ' ').split(' ')
 
 for (node in Jenkins.instance.nodes) {
   computer = node.toComputer()
-  // Skip disconnected nodes
-  if (computer.getChannel() == null) continue
+  // Skip disconnected node
+  if (computer.getChannel() == null) {
+    println("\n======")
+    println("INFO::Skipping ${node.getDisplayName()}, not connected.")
+    continue
+  }
 
+  if (node.getDisplayName() in nodeSkipList) {
+    println("\n======")
+    println("INFO::Skipping ${node.getDisplayName()}, in the skip list.")
+    continue
+  }
   rootPath = node.getRootPath()
 
   size = DiskSpaceMonitor.DESCRIPTOR.get(computer).size
@@ -74,18 +88,63 @@
     }
 
     // get the list of currently used workspaces (to avoid deleting them)
+    //add also the workspaces of the skipped jobs, if any
     lockedWorkspaces = []
+    println('getting executors')
     executors = computer.getExecutors()
+    println('got executors')
     if (executors != null) {
       for (executor in executors) {
-        try {
-          curWorkspace = executor.getCurrentWorkspace()
-          if (curWorkspace != null) {
-            lockedWorkspaces.add(curWorkspace)
-            println("INFO::CURRENTLY 
RUNNING::${curWorkspace.toURI().getPath()}")
+        //try {
+          if (executor == null){
+            println('Empty executor!')
+            continue
           }
-        } catch (all) {
-        }
+          if (executor.isIdle()) {
+            continue
+          }
+          println('getting build')
+          println(executor)
+          println(executor.getDisplayName())
+          try {
+            build = executor.getCurrentExecutable()
+          } catch (all) {
+            println('Exception getting build from executor')
+            println(executor)
+            println(all)
+            throw all
+          }
+          println('got build')
+          if (build == null) {
+            continue
+          }
+          parent = Executables.getParentOf(build)
+          println('got parent')
+          if (parent == null) {
+            continue
+          }
+          task = parent.getOwnerTask()
+          println('got task')
+          if (task == null) {
+            continue
+          }
+          name = task.getName()
+          println('got name')
+          curWorkspace = executor.getCurrentWorkspace()
+          if (name in jobSkipList) {
+            lockedWorkspaces.add(curWorkspace)
+            println("INFO::SKIPPING::IN JOB SKIP 
LIST::${curWorkspace.toURI().getPath()}")
+            continue
+          }
+          if (curWorkspace == null) {
+            continue
+          }
+          lockedWorkspaces.add(curWorkspace)
+          println("INFO::SKIPPING::CURRENTLY 
RUNNING::${curWorkspace.toURI().getPath()}")
+//        } catch (all) {
+//          println('Got exception!!!!!!')
+//          println(all)
+//        }
       }
     }
     // one off executors also have workspace
@@ -106,6 +165,7 @@
       }
     }
 
+
     baseWorkspace = rootPath.child('workspace')
     mounts = 'not_checked'
     for (jobWorkspace in baseWorkspace.listDirectories()) {
@@ -115,7 +175,7 @@
         continue
       }
       if (workspaceIsIn(jobWorkspace, lockedWorkspaces)) {
-        println("INFO::" + jobWorkspace + "::SKIPPING:: Currently in use")
+        continue
       } else {
         try {
           println("INFO::${jobWorkspace}:: Wiping out")
@@ -156,4 +216,4 @@
     }
   }
 }
-println("======")
+
diff --git a/jobs/confs/yaml/jobs/system/system_cleanup-workspaces.yaml 
b/jobs/confs/yaml/jobs/system/system_cleanup-workspaces.yaml
index 659b628..2006aa0 100644
--- a/jobs/confs/yaml/jobs/system/system_cleanup-workspaces.yaml
+++ b/jobs/confs/yaml/jobs/system/system_cleanup-workspaces.yaml
@@ -3,6 +3,14 @@
     node: master
     triggers:
         - timed: "30 * * * *"
+    parameters:
+        - string:
+            name: SKIP_JOBS
+            description: Comma or space separated list of job namess to skip
+            default: ovirt_live_create_iso
+        - string:
+            name: SKIP_NODES
+            description: Comma or space separated list of nodes to skip
     builders:
         - system-groovy:
             command: !include-raw groovy-scripts/cleanup_workspaces.groovy


-- 
To view, visit http://gerrit.ovirt.org/37565
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I41ed694285a6b0f7a5c57b92fcffd1cc09bd98e9
Gerrit-PatchSet: 1
Gerrit-Project: jenkins
Gerrit-Branch: master
Gerrit-Owner: David Caro <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to