{"record":{"id":"479b6e72b035266e","repo":"theonedev/onedev","slug":"build-number-has-to-be-specified","errorCode":null,"errorMessage":"build number has to be specified","messagePattern":"build number has to be specified","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/web/resource/BuildLogResource.java","lineNumber":53,"sourceCode":"import io.onedev.server.service.ProjectService;\nimport io.onedev.server.util.IOUtils;\n\npublic class BuildLogResource extends AbstractResource {\n\n\tprivate static final long serialVersionUID = 1L;\n\n\tprivate static final String PARAM_PROJECT = \"project\";\n\t\n\tprivate static final String PARAM_BUILD = \"build\";\n\t\n\t@Override\n\tprotected ResourceResponse newResourceResponse(Attributes attributes) {\n\t\tPageParameters params = attributes.getParameters();\n\n\t\tLong projectId = params.get(PARAM_PROJECT).toLong();\n\t\tLong buildNumber = params.get(PARAM_BUILD).toOptionalLong();\n\t\tif (buildNumber == null)\n\t\t\tthrow new IllegalArgumentException(\"build number has to be specified\");\n\n\t\tif (!SecurityUtils.isSystem()) {\n\t\t\tProject project = getProjectService().load(projectId);\t\t\t\n\t\t\tBuild build = getBuildService().find(project, buildNumber);\n\n\t\t\tif (build == null) {\n\t\t\t\tString message = String.format(\"Unable to find build (project: %s, build number: %d)\", \n\t\t\t\t\t\tproject.getPath(), buildNumber);\n\t\t\t\tthrow new EntityNotFoundException(message);\n\t\t\t}\n\t\t\t\n\t\t\tif (!SecurityUtils.canAccessLog(build))\n\t\t\t\tthrow new UnauthorizedException();\n\t\t}\n\t\t\n\t\tResourceResponse response = new ResourceResponse();\n\t\tresponse.setContentType(MimeTypes.OCTET_STREAM);\n\t\t","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/web/resource/BuildLogResource.java#L35-L71","documentation":"BuildLogResource serves build log files for /~resource/buildlogs/... URLs. The 'build' parameter (PARAM_BUILD) must carry the build number; when toOptionalLong() yields null the resource throws IllegalArgumentException(\"build number has to be specified\").","triggerScenarios":"Requesting the build log resource URL without the build number parameter, or with a non-numeric/empty value that cannot be parsed as a Long.","commonSituations":"Manually constructed URLs missing &build=N; scripts interpolating an empty BUILD_NUMBER variable; URL templates copied from other resources with different parameter names.","solutions":["Add the build number parameter, e.g. /~resource/buildlogs?project=1&build=42.","Ensure the variable feeding the URL (e.g. $BUILD_NUMBER in pipeline scripts) is actually set and numeric.","Confirm the parameter name matches PARAM_BUILD for your OneDev version."],"exampleFix":"// before\nGET /~resource/buildlogs?project=1          -> 400\n// after\nGET /~resource/buildlogs?project=1&build=42","handlingStrategy":"validation","validationCode":"if (!Number.isInteger(Number(buildNumber)) || buildNumber === null || buildNumber === '') {\n  throw new Error('build number parameter is required and must be numeric');\n}","typeGuard":"function hasBuildNumber(params) {\n  const n = Number(params.build);\n  return Number.isInteger(n) && n > 0;\n}","tryCatchPattern":"try { const log = await fetchLog(projectId, buildNumber); } catch (e) { if (String(e.message).includes('build number has to be specified')) failFast('BUILD_NUMBER env var is not set'); else throw e; }","preventionTips":["Assert CI variables like BUILD_NUMBER are non-empty before building URLs","Use OneDev's job APIs to obtain the build number rather than guessing","Keep parameter names consistent with the resource documentation"],"tags":["onedev","http","bad-request","ci","build-logs"],"backgroundTag":"missing-required-argument","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"}