I understand after some further reading:
https://issues.jenkins-ci.org/browse/JENKINS-25570
https://issues.jenkins-ci.org/browse/JENKINS-27127

That "mutex" like behavior is not really what the concurrency field is all about. It is more for filtering jobs, allowing a certain number to queue up with others effectively thrown away and failed (the secondary issue here is that it seems to hang and leave stale state).

For the benefit of others, after a bit of experimentation I've achieved what I wanted. To run parallel jobs that are similar and for some element of them the same, such that the common parts of their flow have to be serialized. Hopefully the increment below is "atomic" or at least "atomic enough".

The console noise for the waitUntil is a shame though.

class qLock implements Serializable {
    int id = 0
    List queue = []

    def increment() {
        return ++id
    }
    def acquire_id() {
         id = this.increment()
         this.queue.add(id)
         return id
    }
    def is_ready(int id) {
        return (this.queue.indexOf(id) == 0)
    }
    def release(int id) {
         if (this.is_ready(id)) {
             this.queue.remove(0)
         }
    }
}

node {
    def sleeps = [ : ]
    def ql = new qLock()
    for (int i = 0; i < 4; i++) {
        sleeps["num_${i}"] = { sleep10(ql) }
    }
    parallel(sleeps)
}

def sleep10 (qLock ql) {
    ws {
// try to acquire "lock"
        def id = ql.acquire_id()
        waitUntil {
// wait until it is my turn
            return (ql.is_ready(id))
        }
        stage name: "Sleeping for 10 secs"
        sh "sleep 10"
        ql.release(id)
        stage name: "Sleep finished"
    }
}
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to