After even more investigation it seems that *nested lock() statements are
not supported*. Thats what caused all my headache. When using a single
lock() statement with inversePrecedence:true, and two milestone()
statements, then the LIFO queue for running the integration tests works
like a charm.

Hope this info is helpful to other users!
  stefan.

Den 15 jan. 2017 1:15 em skrev "ST" <st.mailingli...@gmail.com>:

> Found this Jenkins bug which I guess is the cause of my problems, so added
> a comment there:
> https://issues.jenkins-ci.org/browse/JENKINS-40787
>
> On Sun, Jan 15, 2017 at 12:28 AM, ST <st.mailingli...@gmail.com> wrote:
>
>> I'm trying to understand why the construct below doesnt work as I expect
>> it to, but have spent hours over it without success.
>>
>> We use git with many branches, and a multi-branch pipeline in Jenkins to
>> build and test. The total build takes more than an hour, where 90% is
>> integration tests ((see build stage below). When several git push events
>> occur within a few minutes, I want a LIFO queue for the integration tests
>> and I also want to abort any older builds waiting to run the integration
>> tests.
>>
>> I believe that the pipeline code below should do that by lock()'ing per
>> branch. However I'm seeing that when 2 builds are waiting for the lock
>> while an earlier build is running the integration tests, then when that
>> earlier build releases the lock, both of the other two builds can acquire
>> the lock simultaneously and start running integration tests.
>>
>> The lockable resources "integrationTests-<branchName>" get created
>> dynamically, in case that plays any role.
>>
>> Anything I'm missing in my line of thoughts?
>>
>> We run on Jenkins 2.37, with latest version of all pipeline plugins.
>>
>>
>> // ... other stages to build, static code analysis, unit tests etc
>>
>> stage('Integration testing') {
>>     milestone(label: 'IntegrationTests-AttemptingToStart')
>>     String lockResource = "integrationTests-${env.BRANCH_NAME}"
>>     lock(resource: lockResource, inversePrecedence: true) {
>>         try {
>>             integrationTestsStage()
>>         } finally {
>>             echo "Done with all integration tests."
>>             milestone(label:'IntegrationTests-Done') // abort all older
>> builds (for same git branch) that haven't passed this milestone yet
>>         }
>>     }
>> }
>>
>> Anyone any input or helping thoughts? Thanks,
>>  stefan.
>>
>>
>

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CABwQARuA0ZPmZfPpd2wQ%3DOyF-JK2pRmW9JNL%2B_G-bq81yi%2Bq0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to