{"record":{"id":"951ba9c0072c8ac6","repo":"jenkinsci/jenkins","slug":"permalink-produced-no-build","errorCode":null,"errorMessage":"Permalink  produced no build","messagePattern":"Permalink  produced no build","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/hudson/cli/ConsoleCommand.java","lineNumber":59,"sourceCode":"\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 {\n            long pos = n >= 0 ? seek(run) : 0;\n\n            if (follow) {\n                AnnotatedLargeText logText;\n                do {\n                    logText = run.getLogText();\n                    pos = logText.writeLogTo(pos, w);","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/core/src/main/java/hudson/cli/ConsoleCommand.java#L41-L77","documentation":"In `ConsoleCommand.run()`, when BUILD is not numeric (NumberFormatException is caught) but IS a recognized permalink (`job.getPermalinks().get(build)` non-null), the code calls `p.resolve(job)`. If resolve returns null (the permalink exists but points to no run, e.g. 'lastSuccessfulBuild' on a job with no successful build), it throws IllegalStateException 'Permalink <build> produced no build'. The original NumberFormatException is chained as the cause.","triggerScenarios":"Running `java -jar jenkins-cli.jar console <job> lastSuccessfulBuild` (or lastStableBuild/lastFailedBuild) when the job has no build matching that permalink yet — e.g. only failed builds exist so lastSuccessfulBuild resolves to null.","commonSituations":"Querying a new or always-failing job's successful/stable console before any qualifying build exists; permalink corrupted by partial build deletion.","solutions":["Trigger a build that satisfies the permalink first (e.g. obtain a successful build before requesting lastSuccessfulBuild).","Use a concrete build number or `lastBuild` (resolves to the most recent run regardless of result) instead of a result-filtered permalink.","Check `job.getPermalinks()` resolution in a script before invoking the CLI, and fall back to lastBuild when null."],"exampleFix":"// before: no successful build exists yet\n//   java -jar jenkins-cli.jar console myjob lastSuccessfulBuild\n//   -> IllegalStateException: Permalink lastSuccessfulBuild produced no build\n//\n// after: use lastBuild (always present) or a concrete build number\n//   java -jar jenkins-cli.jar console myjob lastBuild","handlingStrategy":"validation","validationCode":"// When using a permalink, resolve it first and fall back gracefully\nPermalink p = job.getPermalinks().get(buildArg);\nif (p != null) {\n    Run<?, ?> r = p.resolve(job);\n    if (r == null) {\n        // no qualifying build yet; use lastBuild instead\n        buildArg = \"lastBuild\";\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer 'lastBuild' (always present) over result-filtered permalinks for fresh/unstable jobs.","Confirm a qualifying build exists before requesting lastSuccessfulBuild/lastStableBuild."],"tags":["jenkins","cli","console","permalink","build"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}