Skip to content

Commit 212df86

Browse files
fixed discovery pile up issue
1 parent 03171c9 commit 212df86

2 files changed

Lines changed: 56 additions & 11 deletions

File tree

private-cicd/Jenkinsfile

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
271296
void 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
}

private-cicd/docs/PRIVATE-CICD-GUIDE.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,9 @@ Label: empty
411411
Reserved by: empty
412412
```
413413

414-
This serializes only short discovery runs. It does not prevent worker builds from compiling concurrently.
414+
This serializes only short discovery runs. It does not prevent worker builds from compiling concurrently. A
415+
discovery run that finds the lock held skips its body and ends `NOT_BUILT` rather than queueing, so a slow poll
416+
cannot accumulate a backlog of discovery builds.
415417

416418
## 11. Clean snapshot contract
417419

@@ -475,6 +477,11 @@ Do not create a GitHub repository webhook. OpenLab is not publicly accessible; G
475477
GitHub, then self-queues one `pull_request` worker per unseen PR head SHA. Create the named Lockable Resource
476478
`cloudstack-presubmit-discovery` to prevent overlapping discovery runs. Do not create a separate poller job.
477479

480+
A `discover` build clones a single commit of `private-cicd/scripts` rather than the full repository, which keeps
481+
each poll well inside the five-minute timer. That shallow clone reads the job's configured Git branch and remote,
482+
so approve those two signatures when Script Security reports them; otherwise the build logs
483+
`Shallow discovery checkout unavailable` and falls back to the slow full checkout.
484+
478485
### Pipeline item
479486

480487
Create a regular Pipeline, not Freestyle, Multibranch, or Organization:
@@ -503,8 +510,9 @@ Trigger.
503510

504511
`Abort superseded run` uses Jenkins internal APIs. Under **Manage Jenkins > In-process Script Approval**, approve
505512
only signatures actually requested by this trusted `WorkflowScript` for obtaining the job, enumerating builds,
506-
reading parameters/environment, and stopping a matching build. Never approve unrelated calls or use **Approve
507-
assuming permission check**. Exact signatures vary by controller/plugin versions.
513+
reading parameters/environment, stopping a matching build, and reading the job's Git branch and remote for the
514+
shallow discovery clone. Never approve unrelated calls or use **Approve assuming permission check**. Exact
515+
signatures vary by controller/plugin versions.
508516

509517
### Parameterized smoke test
510518

@@ -947,7 +955,11 @@ authoritative memory request is 1Gi, limit 8Gi, with Maven heap options `-Xms1g
947955
### Source, Groovy, Maven, package
948956

949957
Source failure: verify full SHA, selected PR/branch ref, reachability, credential, HTTPS `.git` URL, and branch
950-
syntax. Checkout is full, so do not diagnose it as shallow history.
958+
syntax. A worker checkout is full, so do not diagnose it as shallow history. Only `discover` builds clone
959+
shallowly, and they read nothing but `private-cicd/scripts`.
960+
961+
Discovery builds queued behind `cloudstack-presubmit-discovery`: cancel the queued ones, then confirm the loaded
962+
Jenkinsfile skips the lock when held and that the running discovery clones shallowly instead of taking minutes.
951963

952964
Groovy rejection: approve only the reported trusted WorkflowScript signature. Later skipped stages and empty-JUnit
953965
messages are symptoms.

0 commit comments

Comments
 (0)