Allow to deploy the same MCP configuration with different stack names

Change-Id: I302c3e38318994a8b446e86bc0a37fa81f06f3a0
diff --git a/jobs/pipelines/remove-old-jenkins-agents.groovy b/jobs/pipelines/remove-old-jenkins-agents.groovy
new file mode 100644
index 0000000..eb2ccd8
--- /dev/null
+++ b/jobs/pipelines/remove-old-jenkins-agents.groovy
@@ -0,0 +1,60 @@
+import hudson.node_monitors.*
+import hudson.slaves.*
+import java.util.concurrent.*
+
+jenkins = Jenkins.instance
+
+import javax.mail.internet.*;
+import javax.mail.*
+import javax.activation.*
+
+def getEnviron(computer) {
+   def env
+   def thread = Thread.start("Getting env from ${computer.name}", { env = computer.environment })
+   thread.join(2000)
+   if (thread.isAlive()) thread.interrupt()
+   env
+}
+
+def agentAccessible(computer) {
+    getEnviron(computer)?.get('PATH') != null
+}
+
+def numberOfflineNodes = 0
+def numberNodes = 0
+for (agent in jenkins.getNodes()) {
+   def computer = agent.computer
+   numberNodes ++
+   println ""
+   println "Checking computer ${computer.name}:"
+   def isOK = (agentAccessible(computer) && !computer.offline)
+   if (isOK) {
+     println "\t\tOK, got PATH back from agent ${computer.name}."
+
+   } else {
+     numberOfflineNodes ++
+     println "  ERROR: can't get PATH from agent ${computer.name}."
+     //if (computer.isTemporarilyOffline()) {
+     //  if (!computer.getOfflineCause().toString().contains("Disconnected by")) {
+     //    computer.setTemporarilyOffline(false, agent.getComputer().getOfflineCause())
+     //  }
+     //} else {
+     //    //computer.connect(true)
+     //}
+
+     if (computer.isOffline() && !computer.isTemporarilyOffline())
+     {
+       println "!!!! this node will be killed !!!";
+       computer.doDoDelete();
+     }
+   }
+     println('\tcomputer.isOffline: ' + computer.isOffline());
+     println('\tcomputer.isTemporarilyOffline: ' + computer.isTemporarilyOffline());
+     println('\tcomputer.getOfflineCause: ' + computer.getOfflineCause());
+     println('\tcomputer.offline: ' + computer.offline);
+     time = computer.getIdleStartMilliseconds() ;
+     println('\tcomputer.getConnectTime: ' + new Date(time).toString());
+ }
+println ("Number of Offline Nodes: " + numberOfflineNodes)
+println ("Number of Nodes: " + numberNodes)
+