Does jenkins lose ephemeral locks within a single build if unreferenced?

Hello folks! I am trying to use locks in a fairly large matrix project configured using jenkins pipeline. I am trying to use a lock around a step which after release may not immediately acquired. Does the lockable resource get destroyed once it becomes unreferenced?

My pipeline code is somewhat like this

pipeline {
    matrix
        name: OS
        values: "A", "B", "C"
    
    agent { label "mylabel" } //one node with this label
        
    stage 1 // takes 10s
    
    stage 2 // takes 10s (has lock(label: 'tmplock') )

    stage 3 // takes 10s    
}

Iā€™m running into java.lang.IllegalArgumentException: The label does not exist: tmplock. Am I correct in thinking that once ā€œAā€ is processed by stage 2, and is not waiting to be acquired, jenkins deletes it and throws this error?

To make the lock step define an ephemeral resource, you have to provide the resource parameter rather than label.

1 Like