jenkinsci/jenkins · error · IllegalArgumentException

No such build #

Error message

No such build #

What it means

`ConsoleCommand.run()` parses the BUILD argument as an integer; if it succeeds but `job.getBuildByNumber(n)` returns null (no build with that number exists), it throws IllegalArgumentException 'No such build #n'. This is a pure lookup miss: the number is valid syntactically but the run record is absent.

Source

Thrown at core/src/main/java/hudson/cli/ConsoleCommand.java:52

    public String build = "lastBuild";

    @Option(name = "-f", usage = "If the build is in progress, stay around and append console output as it comes, like 'tail -f'")
    public boolean follow = false;

    @Option(name = "-n", metaVar = "N", usage = "Display the last N lines")
    public int n = -1;

    @Override
    protected int run() throws Exception {
        job.checkPermission(Item.READ);

        Run<?, ?> run;

        try {
            int n = Integer.parseInt(build);
            run = job.getBuildByNumber(n);
            if (run == null)
                throw new IllegalArgumentException("No such build #" + n);
        } catch (NumberFormatException e) {
            // maybe a permalink?
            Permalink p = job.getPermalinks().get(build);
            if (p != null) {
                run = p.resolve(job);
                if (run == null)
                    throw new IllegalStateException("Permalink " + build + " produced no build", e);
            } else {
                Permalink nearest = job.getPermalinks().findNearest(build);
                throw new IllegalArgumentException(nearest == null ?
                        String.format("Not sure what you meant by \"%s\".", build) :
                        String.format("Not sure what you meant by \"%s\". Did you mean \"%s\"?",
                                build, nearest.getId()), e);
            }
        }

        OutputStreamWriter w = new OutputStreamWriter(stdout, getClientCharset());
        try {

View on GitHub (pinned to 2e228ff40b)

Solutions

  1. List the job's builds (job page or `java -jar jenkins-cli.jar console <job>` with no number defaults to lastBuild) to find a valid number.
  2. Pass a permalink like `lastBuild`, `lastSuccessfulBuild`, or `lastStableBuild` instead of a numeric build number.
  3. If the build was deleted, restore it from backup or reference an existing build.

Example fix

// before: build 42 does not exist
//   java -jar jenkins-cli.jar console myjob 42
//   -> IllegalArgumentException: No such build #42
//
// after: omit the number to get lastBuild, or use a valid one
//   java -jar jenkins-cli.jar console myjob            // lastBuild
//   java -jar jenkins-cli.jar console myjob lastSuccessfulBuild
Defensive patterns

Strategy: validation

Validate before calling

// Verify the build number exists before requesting its console
int n = Integer.parseInt(buildArg);
Run<?, ?> r = job.getBuildByNumber(n);
if (r == null) {
    throw new IllegalArgumentException("No build #" + n
        + " for " + job.getFullDisplayName() + "; valid range is 1.." + job.getLastBuild().getNumber());
}

Prevention

When it happens

Trigger: Running `java -jar jenkins-cli.jar console <job> <N>` where build N does not exist for the job (never ran, was deleted, or N exceeds the highest build number).

Common situations: Typing a build number that is too large, referencing a deleted build, or querying a freshly created job with no builds.

Related errors


AI-assisted analysis of jenkinsci/jenkins@2e228ff40b (2026-08-14). Data as JSON: /api/errors/0af9326d9c51d4c9. Report an issue: GitHub.