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, but you want one to wait for the other.


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

1 Comments

Display comments as (Linear | Threaded)
  1. The is exactly what I'm lookin for! I'm going to try using this to ductape together sidecar containers in declarative pipelines I'm building in Jenkins.

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.
Markdown format allowed


Submitted comments will be subject to moderation before being displayed.