Thanks Victor, I'll take a look at it when I get a chance and see if I can
use your solution.

Cheers,
Guy

On Tue, Aug 15, 2017 at 1:49 PM, Victor Martinez <
[email protected]> wrote:

> I did a kind of similar but not equally implementation. The important bit
> is to try/catch and ensure the last true/false command is in the right
> logic, please read the below:
>
> My use case was to run a certain Integration Test, then if it failed for
> whatever reason, prompt to the user whether to rerun them again with a
> certain timeout to avoid infinite waits.
>
>     stage('TestCase') {
>       steps {
>         script {
>           def filter = 'all'
>           waitUntil {
>             def bRun = build job: 'jobX', propagate: false  // To avoid
> failfast/propagate errors
>             if 
> (bRun.getRawBuild().result.isWorseOrEqualTo(hudson.model.Result.FAILURE))
> {
>               def userInput = true
>               def didTimeout = false
>               def inputValue
>               try {
>                 // Timeout in case to avoid running this forever
>                 timeout(time: 60, unit: 'SECONDS') {
>                   inputValue = input(
>                   id: 'userInput', message: 'jobX failed let\'s rerun
> it?', parameters: [
>                     [$class: 'BooleanParameterDefinition', defaultValue:
> true, description: '', name: 'Please confirm you agree with this']
>                   ])
>                 }
>               } catch(err) { // timeout reached or input false
>                 echo err.toString()
>                 def user = err.getCauses()[0].getUser()
>                 if('SYSTEM' == user.toString()) { // SYSTEM means timeout.
>                   didTimeout = true
>                 } else {
>                   userInput = false
>                   echo "Aborted by: [${user}]"
>                 }
>               }
>               if (didTimeout) {
>                 echo "no input was received before timeout"
>                 false // false will cause infinite loops but it's a way to
> keep retrying, otherwise use true and will exit the loop
>               } else if (userInput == true) {
>                 echo "this was successful"
>                 false // if user answered then iterate through the loop
> again
>               } else {
>                 echo "this was not successful"
>                 currentBuild.result = 'ABORTED'
>                 true  // if user aborted the input then exit the loop
>               }
>             } else {
>               currentBuild.result = 'SUCCESS'
>               true  // if build finished successfully as expected then
> exit the loop
>             }
>           }
>         }
>       }
>     }
>
> The above snippet was based on the below how-to:
> - https://support.cloudbees.com/hc/en-us/articles/
> 226554067-Pipeline-How-to-add-an-input-step-with-timeout-
> that-continues-if-timeout-is-reached-using-a-default-value
>
> I hope it helps
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Jenkins Users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/jenkinsci-users/upVzT3SOZy8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-users/dc49bafb-5772-4f03-9ff3-81bb465a8953%40googlegroups.
> com
> <https://groups.google.com/d/msgid/jenkinsci-users/dc49bafb-5772-4f03-9ff3-81bb465a8953%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CANNH9mvPMt4dB5aMuhiDJdZ3vHsiADiiSdS_L%2BfxeDym8h2rbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to