{"record":{"id":"0af9326d9c51d4c9","repo":"jenkinsci/jenkins","slug":"no-such-build","errorCode":null,"errorMessage":"No such build #","messagePattern":"No such build #","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/hudson/cli/ConsoleCommand.java","lineNumber":52,"sourceCode":"    public String build = \"lastBuild\";\n\n    @Option(name = \"-f\", usage = \"If the build is in progress, stay around and append console output as it comes, like 'tail -f'\")\n    public boolean follow = false;\n\n    @Option(name = \"-n\", metaVar = \"N\", usage = \"Display the last N lines\")\n    public int n = -1;\n\n    @Override\n    protected int run() throws Exception {\n        job.checkPermission(Item.READ);\n\n        Run<?, ?> run;\n\n        try {\n            int n = Integer.parseInt(build);\n            run = job.getBuildByNumber(n);\n            if (run == null)\n                throw new IllegalArgumentException(\"No such build #\" + n);\n        } catch (NumberFormatException e) {\n            // maybe a permalink?\n            Permalink p = job.getPermalinks().get(build);\n            if (p != null) {\n                run = p.resolve(job);\n                if (run == null)\n                    throw new IllegalStateException(\"Permalink \" + build + \" produced no build\", e);\n            } else {\n                Permalink nearest = job.getPermalinks().findNearest(build);\n                throw new IllegalArgumentException(nearest == null ?\n                        String.format(\"Not sure what you meant by \\\"%s\\\".\", build) :\n                        String.format(\"Not sure what you meant by \\\"%s\\\". Did you mean \\\"%s\\\"?\",\n                                build, nearest.getId()), e);\n            }\n        }\n\n        OutputStreamWriter w = new OutputStreamWriter(stdout, getClientCharset());\n        try {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/core/src/main/java/hudson/cli/ConsoleCommand.java#L34-L70","documentation":"`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.","triggerScenarios":"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).","commonSituations":"Typing a build number that is too large, referencing a deleted build, or querying a freshly created job with no builds.","solutions":["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.","Pass a permalink like `lastBuild`, `lastSuccessfulBuild`, or `lastStableBuild` instead of a numeric build number.","If the build was deleted, restore it from backup or reference an existing build."],"exampleFix":"// before: build 42 does not exist\n//   java -jar jenkins-cli.jar console myjob 42\n//   -> IllegalArgumentException: No such build #42\n//\n// after: omit the number to get lastBuild, or use a valid one\n//   java -jar jenkins-cli.jar console myjob            // lastBuild\n//   java -jar jenkins-cli.jar console myjob lastSuccessfulBuild","handlingStrategy":"validation","validationCode":"// Verify the build number exists before requesting its console\nint n = Integer.parseInt(buildArg);\nRun<?, ?> r = job.getBuildByNumber(n);\nif (r == null) {\n    throw new IllegalArgumentException(\"No build #\" + n\n        + \" for \" + job.getFullDisplayName() + \"; valid range is 1..\" + job.getLastBuild().getNumber());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to 'lastBuild' or omit the BUILD argument instead of guessing a number.","In automation, resolve the build via the job's last build number from the API before passing a specific N."],"tags":["jenkins","cli","console","build","log"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}