Akom's Tech Ruminations

Various tech outbursts - code and solutions to practical problems

Jenkins Pipeline: parallel and waitUntil, waiting until the other branch finishes

Posted by Admin • Monday, January 22. 2018 • Category: DevOps

Let's say that for the sake of speed, you are running two slow things in parallel:

parallel one: {
    node {
        sh "sleep 15"
    }
}, two: {
    node {
        //slow part:
        sh "sleep 10"  

        // now do something that needs "one" to finish.  There is a good chance that this will run too soon...
        sh 'wget http://something' //for example
    }
}
 

The problem, obviously, is that you can't be sure that the wget will run after part one finishes. (Let's assume that part one creates the file).


Strangely enough, this actually works:


def flag = false

parallel one: {
    node {
        sh "sleep 15"
        flag = true
    }
}, two: {
    node {
        sh "sleep 10"
        // block until "one" finishes
        waitUntil {
            flag
        }
        echo "Condition reached, we can run the rest now"
    }
}
 

0 Trackbacks

  1. No Trackbacks

0 Comments

Display comments as (Linear | Threaded)
  1. No comments

Add Comment


You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

What is the primary language of this blog? (Anti-SPAM question)


Submitted comments will be subject to moderation before being displayed.