@@ -266,6 +266,31 @@ def validateInventory(Map inventory) {
266266 return enabledVms
267267}
268268
269+ // Discovery only needs list-eligible-prs.py, so it fetches one commit without
270+ // tags and checks out only private-cicd/scripts. A full checkout of CloudStack
271+ // takes minutes and makes each poll outlast the next timer trigger.
272+ // The GitSCM getters are sandboxed, so fall back to the full checkout when the
273+ // controller has not approved them yet.
274+ void checkoutDiscoveryScripts () {
275+ try {
276+ checkout([
277+ $class : ' GitSCM' ,
278+ branches : scm. branches,
279+ userRemoteConfigs : scm. userRemoteConfigs,
280+ extensions : [
281+ [$class : ' CloneOption' , shallow : true , depth : 1 , noTags : true ],
282+ [
283+ $class : ' SparseCheckoutPaths' ,
284+ sparseCheckoutPaths : [[path : ' private-cicd/scripts' ]]
285+ ]
286+ ]
287+ ])
288+ } catch (Exception e) {
289+ echo " Shallow discovery checkout unavailable, using the full checkout: ${ e} "
290+ checkout(scm)
291+ }
292+ }
293+
269294// Optional manual gate after a stage, enabled by PAUSE_BETWEEN_STAGES.
270295// The pod stays reserved while an input waits, so the timeout is required.
271296void pauseForVerification (String stageName ) {
@@ -593,12 +618,23 @@ spec:
593618 }
594619 }
595620 steps {
596- lock(resource : ' cloudstack-presubmit-discovery' ) {
621+ script {
622+ currentBuild. displayName =
623+ " #${ env.BUILD_NUMBER} discover PR revisions"
624+ currentBuild. description =
625+ ' skipped, another discovery run held the lock'
626+ // NOT_BUILT prevents every worker stage and notification
627+ // below, including when the lock is skipped. The next poll
628+ // reads PRESUBMIT_DISCOVERY_NEXT_WATERMARK, which only a
629+ // run that reached the end of the lock body sets.
630+ currentBuild. result = ' NOT_BUILT'
631+ }
632+ // Skipping instead of queueing keeps a slow poll from building
633+ // a backlog of discovery runs that each hold an agent pod.
634+ lock(resource : ' cloudstack-presubmit-discovery' , skipIfLocked : true ) {
597635 script {
598- currentBuild. displayName =
599- " #${ env.BUILD_NUMBER} discover PR revisions"
600636 deleteDir()
601- checkout(scm )
637+ checkoutDiscoveryScripts( )
602638 if (! (params. EXPECTED_REPOSITORY ==~ / ^[A-Za-z0-9_.-]+\/ [A-Za-z0-9_.-]+$/ )) {
603639 error(' EXPECTED_REPOSITORY must be owner/repository.' )
604640 }
@@ -706,9 +742,6 @@ spec:
706742 currentBuild. description = isInitialDiscovery ?
707743 " seeded at ${ watermark} ; queued ${ queuedCount} ; deferred ${ deferredCount} " :
708744 " since ${ watermark} ; queued ${ queuedCount} ; deferred ${ deferredCount} "
709- // NOT_BUILT prevents every worker stage and notification
710- // below. The next poll reads PRESUBMIT_DISCOVERY_NEXT_WATERMARK.
711- currentBuild. result = ' NOT_BUILT'
712745 }
713746 }
714747 }
0 commit comments