---
name: jenkins-recon
description: Investigate the state of a Jenkins instance through its REST API, console logs, thread dumps, and container logs — build failures, hangs and stalls, queue backlogs, lock contention, restarts and deploys, capacity, and verifying whether a change or fix actually took effect. Use for any Jenkins-wide reconnaissance question — how many builds hit some error, why builds are stuck or slow, when something started, what is blocking what, whether a config change applied, or whether a fix held.
title: jenkins-recon
canonical_url: https://skilld.dev/gh/straub/agent-skills/jenkins-recon
last_updated: 2026-10-18T07:11:08.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [scripts/grep-builds.sh](https://skilld.dev/api/skills-raw/straub/agent-skills/jenkins-recon/scripts/grep-builds.sh).
>
> If the user asked to install this Skill, run `npx skilld install straub/agent-skills/jenkins-recon`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/jenkins-recon`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/straub/agent-skills/jenkins-recon) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/jenkins-recon`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/jenkins-recon --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/jenkins-recon --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Jenkins Recon

Techniques for investigating build failures across a Jenkins organization folder
(multibranch projects, many jobs × many branches) without drowning in requests or
false positives.

## Use curl, not WebFetch, for the Jenkins API

`WebFetch` pipes content through a summarizing model — it will silently truncate a
large JSON response (e.g. hundreds of jobs) down to a couple of entries with no
warning. Hit the JSON API directly with `curl` and parse it yourself
(`python3 -c 'import json...'` or `jq`). Pass `-g` (`--globoff`). The `[`/`]` in a `tree=` param are not a shell problem —
**curl** treats them as its own URL-globbing syntax, rejects `[name]` as a bad
range, and writes **nothing** to stdout. It exits **3**, but `-s` suppresses the
`curl: (3) bad range in URL` diagnostic, so with `-s` you see only an empty body.
Check the exit status rather than inferring from empty output — and note that a
`;` or another command between the pipeline and `${PIPESTATUS[0]}` clobbers it,
which is an easy way to convince yourself curl succeeded when it did not.

```bash
curl -sg -n "https://<jenkins>/job/<org-folder>/api/json?tree=jobs[name]"
```

`-g` keeps the query readable; percent-encoding as `%5B`/`%5D` also works if you
prefer. `-n` uses `~/.netrc` for auth.

## `tree=` shapes for multibranch org folders

- All branch jobs' current status:
  `jobs[name,jobs[name,lastBuild[number,result,timestamp,url]]]`
- Last N builds per branch (recent history without walking every job):
  `jobs[name,jobs[name,builds[number,result,timestamp,url]{0,N}]]`
- Scope to one job's branches directly (skip the org-folder nesting) by hitting
  `.../job/<org-folder>/job/<project>/api/json?tree=...` instead.

## Scope ladder — don't ask for everything at once

A single `builds{0,50}` query across every job in a large org folder can time out
when the folder contains many jobs. Narrow before you widen:

1. **Sweep**: org-wide `lastBuild`-only query (cheap, one request) to see current
   state everywhere.
2. **Filter**: in Python/jq, keep only what's in the time window you care about.
3. **Drill down**: only *then* fetch per-branch `builds{0,N}` history, and only for
   the subset of projects/branches that survived step 2.

This also applies to console-log checks: don't fetch `consoleText` for every build
you have URLs for if a cheaper filter (result, timestamp) can shrink the list first.

## Don't trust the named scope when shared infrastructure is involved

If the thing being investigated could stem from infrastructure shared across org
folders — a global library cache, a lock, a shared executor pool — the org
folder(s) named in the request are not necessarily the whole blast radius. On
2026-08-12 a lock holder lived in a folder nobody had mentioned, with waiters in
two more; the request named only two of the five that mattered. Sweep every org
folder on the instance (`curl .../api/json?tree=jobs[name]` at the root lists
them) or explicitly confirm scope before concluding a root cause is isolated to
the folders named up front.

## Finding the true first-failed stage via `wfapi/describe`

A multi-stage pipeline build's overall `result: FAILURE` doesn't tell you which
stage actually broke — one root failure (e.g. a test container dying) cascades
into every downstream stage also reporting FAILED, so the last failed stage in
the summary view is often a symptom, not the cause. Pipeline builds expose a
stage-level breakdown at:

```bash
curl -sS "<build-url>/wfapi/describe"
```

This returns each stage's `name`, `status`, and `startTimeMillis`. Sort by start
time and take the *first* stage with `status: FAILED` (a later `status: ABORTED`
usually just means Jenkins killed the rest of the pipeline after that earlier
failure) — that's the real root stage. Scope your log-reading to that stage
specifically rather than assuming the last FAILED stage mentioned is where the
problem started.

## Grep the failure, not a filename that also appears in success logs

A build log can mention the same filename/string in both a success message and an
error message. Matching on a substring like a bare filename will overcount — one
investigation went from ~40 true positives to over 1,000 by matching on a build
artifact's filename (e.g. `"some-manifest.json"`) instead of the actual failure
line (e.g. `"Error: ENOENT: no such file or directory, open '/path/to/some-manifest.json'"`).
Always grep the most specific fragment of the *actual error/exception text*, not
just an artifact name that could appear in unrelated log lines. Verify by manually
reading one matched log before trusting the count.

The same caution applies in reverse: a surprising **zero** matches from an
exact-string grep doesn't necessarily mean the error is absent — part of the
line can vary between occurrences (a resolved hostname, a container ID, a
dynamic port) even though it's the same underlying failure. If zero seems
wrong, loosen the pattern to a more stable substring, then manually verify
each hit before trusting that count either.

Two more variants of "the pattern quietly disagrees with reality", both of which
cost real time on a 2026-08-12 investigation:

- **Ref-name variants.** Exact-matching `Could not find origin/HEAD` missed every
  `Could not find refs/remotes/origin/HEAD`, undercounting the bucket for several
  cycles and masking the one build that actually held the lock. When a version or
  ref string can be spelled more than one way, match the stable fragment.
- **A missing line is itself a state.** Classifying on the *presence* of a line
  assumes every healthy build prints it. When a shared library is served from
  cache it never prints `Attempting to resolve`, so a classifier keyed on that
  bucketed 326 perfectly healthy builds as "unknown". Before trusting a bucket,
  ask what a *successful* build omits.

Use `scripts/grep-builds.sh` to check a list of build URLs for an exact string in
their console output (see script for usage — handles the parallelism gotchas below).

## Thread dumps when builds are stuck rather than failing

A stalled build often shows nothing useful in its own console — the last line is
whatever printed before it blocked, and the REST API just reports `building: true`.
The controller-wide thread dump is what identifies the blocker.

```bash
curl -sfg -n "https://<jenkins>/threadDump" -o /tmp/td.txt \
  || { echo "threadDump fetch failed (403? see below)"; exit 1; }
grep -oE 'owned by "[^"]*" Id=[0-9]+' /tmp/td.txt | sort | uniq -c | sort -rn | head
```

`-f` matters here. Without it a 403 still writes an HTML error body to the file,
the grep matches nothing, and the empty result reads exactly like "no lock
contention" — the most dangerous possible misreading of this check.

Ranking by waiter count immediately names the contended locks and who holds them.
Then pull the owner's own stack (search its `Id=` where it is *not* preceded by
`owned by`) to see what the holder is actually doing — that distinguishes "holder
is doing slow legitimate work" from "holder is itself blocked on something else".

Watch for stacked locks: on 2026-08-12 a build held a fair `ReentrantReadWriteLock`
while itself parked on a JVM-global `ReentrantLock` one layer down, so ~850 threads
queued behind two `git fetch` subprocesses. The console showed only the first
symptom; only the dump showed the chain.

Note the last console line pins the blocking call precisely — if a known code path
prints X then immediately takes a lock, a log ending at X *is* the lock wait.

## When the endpoints you need return 403

A token can read `/api/json` fine and still be refused the diagnostic endpoints —
`/threadDump`, `/configuration-as-code/export`, and `/manage/configure` all 403 for
a non-admin token. They return a short HTML body along with the 403, so a bare
`curl -s ... | grep` looks like a clean, empty result.

Check the status explicitly — `-w '%{http_code}'` or `-f` — rather than guessing
from response size. Body length varies with proxies and customised error pages and
is not a reliable discriminator.

When config is unreadable, infer it from behaviour instead of giving up: pick an
observable whose rate or timing differs between the candidate values and measure
that. Prefer this even when you *can* read the config — it tests what is in effect,
not what is displayed.

## Inferring a blocked config value from event frequency

The general form of the pointer above: if a config value gates how *often* some
observable event fires, count that event over a time window and compare the rate
against what each candidate value would predict. A refresh/TTL-style setting is
the clean case — a short interval produces a rate roughly an order of magnitude
higher than a long one, so a handful of occurrences in 30 minutes is enough to
tell 5-minute from 90-minute apart without ever reading the value.

## `lastBuild`-only sampling hides stuck builds

Sweeping `jobs[name,jobs[name,lastBuild[...]]]` is cheap and usually right, but a
stuck build silently leaves your sample the moment a newer build starts on the same
branch. A falling "stuck" count can therefore mean supersession, not recovery.

The robust fix is to stop sampling and start tracking: retain the specific build
IDs/URLs you first observed and re-poll *those*, so a build leaving the sample is
distinguishable from a build finishing.

Queue-head movement is a useful secondary signal but proves less than it appears.
A head that never moves is worth investigating — on 2026-08-12 a count drifted
downward for ~50 minutes while the head sat still — but it does not by itself mean
nothing is draining, since one permanently blocked item can pin the head while
other builds start and finish behind it. Treat it as a prompt to look, not a
conclusion.

## Open-ended triage when you don't know the error text yet

The exact-string grep above assumes you already know what you're looking for.
When the task is "categorize the causes of these failures" rather than "did
error X recur," there's no string to grep for yet — you have to discover it:

1. **Sample, don't scan everything.** Pull a manageable set of failed builds
   (e.g. one recent failure per project, or the last N failures per job) rather
   than every failure across every branch — full coverage on unknown-shape data
   is expensive and mostly redundant once you've seen a few instances of each
   distinct cause.
2. **Pull a log window around the failure, not the whole log.** Use the failing
   stage from `wfapi/describe` above to scope which part of `consoleText` to
   read, or just check the tail — don't read an entire build log to find one
   error.
3. **Extract each build's failure signature and cluster.** Pull out the actual
   error line/exception from each sampled build and group builds by matching
   signature. A signature that recurs across *unrelated* jobs/repos is a real,
   systemic cause worth flagging first; one confined to a single job/build is
   more likely one-off flakiness.
4. **Filter to the stage(s) the question is actually about.** If you're asked
   to categorize failures in a specific stage (e.g. "why are the E2E tests
   flaky"), use the first-failed-stage from `wfapi/describe` to separate builds
   that failed *in* that stage from builds that never reached it because an
   earlier, unrelated stage failed first. A build that failed before the stage
   in scope isn't an instance of the thing you were asked about, even though
   its overall pipeline result is also FAILURE. Mention out-of-scope upstream
   failures as a brief aside if they're notably common — they may be worth a
   separate investigation — but don't fold their counts into the category you
   were asked to categorize.
5. **Only then scale up precisely.** Once a signature looks like the dominant
   cause, switch to the exact-string workflow above (`grep-builds.sh`) to get
   an accurate count across the full build set for that specific cause.
6. **Report what you sampled vs. skipped.** State the actual coverage (e.g.
   "one most-recent-failure per project, not full history") so a categorization
   from a sample isn't mistaken for an exhaustive count.

## Tracing a shared Jenkins library commit to its PR

When builds check out a shared library (`Loading library <name>@...` /
`Checking out Revision <sha>` in the console log), you can go from "these builds all
picked up revision X" to a real causal story:

1. Grab the shared-library revision from console logs of a last-good build and a
   first-bad build for the same job — if they differ, that's your suspect commit range.
2. Find the PR that introduced it:
   `gh api repos/<org>/<lib-repo>/commits/<sha>/pulls`
   → gives PR number, title, diff, and `merged_at` timestamp.
3. Diff the two revisions directly:
   `gh api repos/<org>/<lib-repo>/compare/<old-sha>...<new-sha> --jq '.files[].patch'`
4. Compare `merged_at` against the first-failure timestamp from the Jenkins data —
   minutes-level alignment across multiple independently-triggered jobs is strong
   causal evidence, not coincidence.
5. If the library step just wraps scripts from another package (e.g. a
   `node_modules/@org/pkg/bin/*.sh` shim), fetch that package's repo too
   (`gh api repos/<org>/<pkg-repo>/contents/<path>`) — the real logic, and the real
   fix, is often one level deeper than the shared-library `vars/*.groovy` file.

## Parallelizing console-log checks (BSD xargs gotchas)

On macOS, `xargs` is BSD xargs, not GNU:

- No `-a file` flag — pipe input instead: `cat urls.txt | xargs -P 8 -I{} ...`
- macOS ships bash 3.2: no associative arrays (`declare -A` fails with
  `invalid option`). A wrapper script avoids this too.
- Inline `bash -c '...'` with several layers of quoting embedded in `-I{}` can fail
  with `xargs: command line cannot be assembled, too long` even for a short,
  reasonable-looking command. Write a small wrapper script and call that from
  `-I{}` instead of inlining the logic — see `scripts/grep-builds.sh`.

## Before/after verification when checking if a fix held

Don't stop at "0 matches" — that can mean "fixed" or "I didn't check the right
builds." Re-run the *same* precise grep against builds from after the fix landed,
across enough volume to be meaningful (a handful of builds in the first hour is
weak evidence; a day's worth of real traffic including some unrelated failures is
strong evidence). For any build that still fails post-fix, read its console log
manually to confirm the failure is unrelated rather than assuming a clean bill of
health.

## Running the same check on a recurring cadence

When a fix or an incident needs watching over many cycles rather than one-shot
verification, match the check interval to how fast the signal is actually
changing, not to a fixed default — tight (10–15s) right after a risky event like
a deploy or restart where the interesting window is the first couple of minutes,
5 minutes for ordinary steady-state watching, 10+ minutes or stopping entirely
once several consecutive cycles have shown nothing. Widen or narrow explicitly
rather than leaving one cadence running out of inertia. (A 5-minute default also
happens to sit comfortably inside typical prompt-cache TTLs, so it's a reasonable
starting point on cost grounds alone — but that's a token-cost argument, not a
signal-value one; let the actual rate of change move you off it in either
direction.)

If you're reporting an ETA (e.g. "backlog clears in ~N minutes") derived from a
trend across your own prior checks, say so explicitly and state it as a range
when the trend is noisy rather than a single confident number — a metric that
oscillates rather than monotonically drains will make a point estimate look more
precise than the data supports.

Engaging a maintenance/quiet-down mode to stop new arrivals is a legitimate
diagnostic move here, not just an operational safety step — freezing arrivals is
often the only way to tell whether something is truly draining versus being
masked by churn (new items arriving as fast as old ones resolve).

**It is controller-wide, so it is not yours to engage.** It blocks every queued
build on the instance, including work belonging to teams with no connection to the
incident, and it does not survive a restart. Recommend it to the operator with the
expected duration and how it will be lifted, and let a human make the call — the
diagnostic value never justifies unilaterally halting an instance.

When deciding whether to escalate mid-watch, don't fire on one raw number alone.
A single metric crossing a threshold is often a sampling artifact of whatever
you're polling, not a real state — prefer requiring two or more correlated
signals together (e.g. "the specific thing you'd blame is actually present" AND
"the downstream count is elevated"), and check whether it's the *same* items
persisting across consecutive samples rather than just whether a count stays
high. A count that holds steady while its members completely turn over isn't
persistence; a count that swings while one specific item never moves is.
