Giter Site home page Giter Site logo

concurrent-step-plugin's Introduction

Jenkins Concurrent Step Plugin

Jenkins plugin to synchronize status among parallel stages in pipeline.
** This plugin steps can't recover from Jenkins crash and can only be used in pipeline script **

Block and Asynchronous

This plugin doesn't block the pipeline main thread. It leverages Jenkins asynchronous execution so the parallel stages continue to execute in other branches.

Barrier

def barrier = createBarrier count: 3;
boolean out = false
parallel(
        await1: {
            awaitBarrier barrier
            echo "out=${out}"
        },
        await2: {
            awaitBarrier (barrier){
                sleep 2 //simulate a long time execution.
            }
            echo "out=${out}"
        },
        await3: {
            awaitBarrier (barrier){
                sleep 3 //simulate a long time execution.
                out = true
            }
            echo "out=${out}"
        }
)

Latch

def latch = createLatch count: 2;
def var1 = false;
def var2 = false;
parallel(
        wait: {
            awaitLatch latch
            echo "var1=${var1}"
            echo "var2=${var2}"
        },
        countdown1: {
            countDownLatch (latch) {
                sleep 3 //simulate a long time execution.
                var1 = true
            }
        },
        countdown2: {
            countDownLatch (latch) {
                sleep 2 //simulate a long time execution.
                var2 = true
            }
        }
)

Semaphore

def semaphore = createSemaphore permit:1
def out2=0
parallel(
        semaphore1: {
            acquireSemaphore (semaphore){
                echo "out1 1"   //actions after acurire a semaphore and before release The semaphore is automatically released
                sleep 3
                out2=2
            }
        },
        semaphore2: {
            sleep 1
            acquireSemaphore (semaphore){
                echo "out2 ${out2}"
            }
        }
)

Condition

def condition = createCondition()
def out = false
parallel(
        wait1: {
            awaitCondition condition
            echo "out=${out}"
        },
        wait2: {
            awaitCondition condition
            echo "out=${out}"
        },
        signalAll: {
            signalAll (condition:condition) {
                sleep 3 //simulate a long time execution.
                out = true
            }
        }
)

Release Steps with closure body

It usually requires try/finally handling in release branch. To simplify pipeline code, all release steps has an optional closure parameter. The lock will be released immediately after closure code is executed even an exception is thrown in the block.
Because of its semantic, Semaphore block closure is a parameter of acquireSemaphore and should not release the lock manually again.

Samples

See more samples at src/test/resources

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.