{"record":{"id":"1fb227196c34788b","repo":"theonedev/onedev","slug":"unable-to-find-build-project-s-build-number-1fb227","errorCode":null,"errorMessage":"Unable to find build (project: %s, build number: %d)","messagePattern":"Unable to find build \\(project: (.+?), build number: (.+?)\\)","errorType":"exception","errorClass":"EntityNotFoundException","httpStatus":404,"severity":"error","filePath":"server-plugin/server-plugin-report-unittest/src/main/java/io/onedev/server/plugin/report/unittest/TestArtifactResource.java","lineNumber":56,"sourceCode":"\n\tprivate static final String PARAM_BUILD = \"build\";\n\n\tprivate static final String PARAM_REPORT = \"report\";\n\n\t@Override\n\tprotected ResourceResponse newResourceResponse(Attributes attributes) {\n\t\tvar params = attributes.getParameters();\n\t\tvar projectId = params.get(PARAM_PROJECT).toLong();\n\t\tvar buildNumber = params.get(PARAM_BUILD).toLong();\n\t\tString reportName = params.get(PARAM_REPORT).toString();\n\t\tif (reportName.contains(\"..\"))\n\t\t\tthrow new ExplicitException(\"Invalid request path\");\n\n\t\tif (!SecurityUtils.isSystem()) {\n\t\t\tvar project = OneDev.getInstance(ProjectService.class).load(projectId);\n\t\t\tvar build = OneDev.getInstance(BuildService.class).find(project, buildNumber);\n\t\t\tif (build == null) {\n\t\t\t\tthrow new EntityNotFoundException(String.format(\n\t\t\t\t\t\t\"Unable to find build (project: %s, build number: %d)\",\n\t\t\t\t\t\tproject.getPath(), buildNumber));\n\t\t\t}\n\t\t\tif (!SecurityUtils.canAccessReport(build, reportName))\n\t\t\t\tthrow new UnauthorizedException();\n\t\t}\n\n\t\tList<String> pathSegments = new ArrayList<>();\n\t\tfor (int i = 0; i < params.getIndexedCount(); i++) {\n\t\t\tString pathSegment = params.get(i).toString();\n\t\t\tif (pathSegment.contains(\"..\"))\n\t\t\t\tthrow new ExplicitException(\"Invalid request path\");\n\t\t\tif (pathSegment.length() != 0)\n\t\t\t\tpathSegments.add(pathSegment);\n\t\t}\n\t\tString artifactPath = Joiner.on(\"/\").join(pathSegments);\n\t\tif (!artifactPath.startsWith(ARTIFACTS + \"/\"))\n\t\t\tthrow new ExplicitException(\"Invalid artifact request path\");","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-plugin/server-plugin-report-unittest/src/main/java/io/onedev/server/plugin/report/unittest/TestArtifactResource.java#L38-L74","documentation":"For non-system requests, the resource loads the project, then looks up the build via BuildService.find(project, buildNumber). If no build with that number exists in the project it throws EntityNotFoundException(\"Unable to find build (project: %s, build number: %d)\"). This validates that the artifact request targets a real build before any permission checks or file access.","triggerScenarios":"Calling the test artifact resource with a build number that does not exist in the given project — wrong project id paired with a valid build number, a deleted build, or a build from another project.","commonSituations":"Copy-pasted URLs across projects; builds removed by cleanup/retention policies; script caching an old build id; off-by-one in an automation loop enumerating build numbers.","solutions":["Verify the project id and build number pair via the project's build list or REST API.","Confirm the build wasn't deleted by retention/cleanup rules.","Update the script/config to resolve the latest build dynamically instead of hard-coding numbers.","Ensure you are querying the project that actually owns the build."],"exampleFix":"// before\nlong buildNumber = 42; // hard-coded, build deleted\n\n// after\nBuild build = oneDev.buildQueryManager().find(project, \"$ latest\");\nlong buildNumber = build.getNumber();","handlingStrategy":"try-catch","validationCode":"# resolve latest build before requesting artifacts\nconst builds = await api.get(`/projects/${projectId}/builds?offset=0&count=1`);\nconst buildNumber = builds[0].number;","typeGuard":null,"tryCatchPattern":"try {\n  downloadTestArtifact(projectId, buildNumber, reportName, artifactPath);\n} catch (e) {\n  if (/Unable to find build/.test(e.message)) {\n    console.error(`Build #${buildNumber} not found in project ${projectId}; refresh build reference`);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Resolve build numbers dynamically instead of hard-coding them.","Verify project/build pairing when copying URLs.","Account for retention/cleanup deleting old builds."],"tags":["entity-not-found","build","rest-api"],"backgroundTag":"entity-not-found","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}