I have the same problem so I'm very interested in a solution...
I have tried everything I can think of. I'm currently locking on the
outmost level, so that every stage and node blocks is inside the lock. I
previously had it inside a node block but got the impression that the lock
only worked on the same node. But setting it on the outmost level still
fails sometimes, even for jobs execited on the same node...
So I think this is a bug somehow...
/Thomas
Den fredag 7 april 2017 kl. 17:24:32 UTC+2 skrev Jonathan del Strother:
>
> Are pipeline locks expected to behave when used by two nodes
> simultaneously?
>
> My Jenkinsfile defines the following helper -
>
> def log(msg) {
> echo((new Date().format("yyyy-MM-dd'T'HH:mm:ss: ")) + msg)
> }
>
> def lockDB(number, callback) {
> try {
> log "${number}: Acquiring lock ..."
> lock(resource: "boom-test-database-${number}", inversePrecedence:
> true) {
> log "${number}: Acquired!"
> callback()
> log "${number}: Releasing..."
> }
> } finally {
> log "${number}: Released!"
> }
> }
>
>
> I somewhat frequently see two nodes manage to acquire the same lock
> simultaneously, as in the following example, where master locked a resource
> from 14:45:57 -> 14:52:04, and the slave locked the same resource
> from 14:51:24 -> 14:56:43.
>
>
> [featureTests] Running on master in
> /var/jenkins_home/workspace/BoomMultiPipeline_master-YRHUUT2RENAD5FNHS4YJ5GQKTJDN2M7B3KGAU3ELBWX7MZ2AEKBA
> [featureTests] 2017-04-07T14:40:44: 1: Acquiring lock ...
> [Pipeline] [featureTests] lock
> [featureTests] Trying to acquire lock on [boom-test-database-1]
> [featureTests] Found 0 available resource(s). Waiting for correct amount:
> 1.
> [featureTests] [boom-test-database-1] is locked, waiting...
> [featureTests] Lock acquired on [boom-test-database-1]
> [featureTests] 2017-04-07T14:45:57: 1: Acquired!
> ... running tests
> [featureTests] Lock released on resource [boom-test-database-1]
> [featureTests] 2017-04-07T14:52:04: 1: Released!
>
>
>
>
> [featureTests] Running on slave in
> /var/jenkins_home/workspace/eline_tb_remaining_indices2-DTE7IMSYRVCF6GO3T5IRRR52R4YQ3GSRFNEEKCRH7FGSUBQB4SFQ
> [featureTests] 2017-04-07T14:49:33: 1: Acquiring lock ...
> [Pipeline] [featureTests] lock
> [featureTests] Trying to acquire lock on [boom-test-database-1]
> [featureTests] Found 0 available resource(s). Waiting for correct amount:
> 1.
> [featureTests] [boom-test-database-1] is locked, waiting...
> [featureTests] Lock acquired on [boom-test-database-1]
> [featureTests] 2017-04-07T14:51:24: 1: Acquired!
> ... running tests
> [featureTests] Lock released on resource [boom-test-database-1]
> [featureTests] 2017-04-07T14:56:43: 1: Released!
>
>
>
> Is this a bug, or am I misunderstanding how locking is supposed to work in
> Jenkins?
>
--
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/d69d5018-5d55-4766-8978-f6b1fd00b197%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.