waitForInputThenPass helper

We need to have a timeout in user input and continue pipeline.
However default behaviour is to fail the job. Unfortunately there
is no easy way to distinguish user abort from timeout. Official
workaround is to look at the user name. But getUser() function
is forbidden by Script Security Plugin. This is why we have to
move this function to pipeline library.

Change-Id: Ic8cfe939f3d2694db49b3413eb246c89f89f9f4f
diff --git a/src/com/mirantis/mk/Common.groovy b/src/com/mirantis/mk/Common.groovy
index 4097b3c..9a82fbe 100644
--- a/src/com/mirantis/mk/Common.groovy
+++ b/src/com/mirantis/mk/Common.groovy
@@ -513,3 +513,29 @@
     currentBuild.result = "FAILURE"
     throw new Exception("Failed after $times retries")
 }
+
+
+/**
+ * Wait for user input with timeout
+ *
+ * @param timeoutInSeconds Timeout
+ * @param options Options for input widget
+ */
+def waitForInputThenPass(timeoutInSeconds, options=[message: 'Ready to go?']) {
+  def userInput = true
+  try {
+    timeout(time: timeoutInSeconds, unit: 'SECONDS') {
+      userInput = input options
+    }
+  } catch(err) { // timeout reached or input false
+    def user = err.getCauses()[0].getUser()
+    if('SYSTEM' == user.toString()) { // SYSTEM means timeout.
+      println("Timeout, proceeding")
+    } else {
+      userInput = false
+      println("Aborted by: [${user}]")
+      throw err
+    }
+  }
+  return userInput
+}