{"record":{"id":"9902ac0f31afc4d7","repo":"theonedev/onedev","slug":"ref-not-found-refname","errorCode":null,"errorMessage":"Ref not found: ${refName}","messagePattern":"Ref not found: (.+?)","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/TriggerJobResource.java","lineNumber":128,"sourceCode":"\t\tThreadContext.bind(subject);\n\t\ttry {\n\t\t\tif (!SecurityUtils.canRunJob(subject, project, job))\t\t\n\t\t\t\tthrow new UnauthorizedException();\n\n\t\t\tif (StringUtils.isNotBlank(branch) && StringUtils.isNotBlank(tag)) \n\t\t\t\tthrow new NotAcceptableException(\"Either branch or tag should be specified, but not both\");\n\t\t\t\n\t\t\tString refName;\n\t\t\tif (branch != null)\n\t\t\t\trefName = GitUtils.branch2ref(branch);\n\t\t\telse if (tag != null)\n\t\t\t\trefName = GitUtils.tag2ref(tag);\n\t\t\telse\n\t\t\t\trefName = GitUtils.branch2ref(project.getDefaultBranch());\n\t\t\t\n\t\t\tRevCommit commit = project.getRevCommit(refName, false);\n\t\t\tif (commit == null)\n\t\t\t\tthrow new NotAcceptableException(\"Ref not found: \" + refName);\n\t\t\t\n\t\t\tMap<String, List<String>> jobParams = new HashMap<>();\n\t\t\tfor (Map.Entry<String, List<String>> entry: uriInfo.getQueryParameters().entrySet()) {\n\t\t\t\tif (!entry.getKey().equals(PARAM_PROJECT) && !entry.getKey().equals(PARAM_BRANCH)\n\t\t\t\t\t\t&& !entry.getKey().equals(PARAM_TAG) && !entry.getKey().equals(PARAM_JOB) \n\t\t\t\t\t\t&& !entry.getKey().equals(PARAM_ACCESS_TOKEN)\n\t\t\t\t\t\t&& !entry.getKey().equals(PARAM_REBUILD_IF_FINISHED)) {\n\t\t\t\t\tjobParams.put(entry.getKey(), entry.getValue());\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tvar build = jobService.submit(user, project, commit.copy(), job, jobParams, refName, \n\t\t\tnull, null, \"Triggered via restful api\");\n\t\t\tif (build.isFinished())\n\t\t\t\tjobService.resubmit(user, build, \"Rebuild via restful api\");\n\t\t\treturn build.getId();\n\t\t} finally {\n\t\t\tThreadContext.unbindSubject();","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/TriggerJobResource.java#L110-L146","documentation":"After resolving refName (from branch, tag, or the project's default branch), triggerJob calls project.getRevCommit(refName, false); a null commit means the ref does not exist in the repository, so NotAcceptableException (406) 'Ref not found: <refName>' is thrown. refName is the fully qualified git ref like refs/heads/main or refs/tags/v1.0.","triggerScenarios":"Triggering with a 'branch' or 'tag' value that does not exist in the repo (typo, deleted branch, unpushed tag), or the project has no resolvable default branch (empty repo or default branch renamed).","commonSituations":"Branch protected/deleted before triggering; tag not pushed yet; misspelled branch name; newly created project with no commits so default-branch resolution fails; branch renamed after updating main pipeline.","solutions":["Verify the branch/tag exists in the repository (git ls-remote) and fix the parameter value.","Push the branch/tag, or set the project's default branch correctly if triggering without branch/tag.","If the repo is empty, make an initial commit before triggering jobs."],"exampleFix":"// before\ncurl 'http://onedev/~api/trigger-job?project=p&job=CI&branch=mian&access_token=T'\n// after (branch exists)\ngit push origin main\ncurl 'http://onedev/~api/trigger-job?project=p&job=CI&branch=main&access_token=T'","handlingStrategy":"validation","validationCode":"const ref = params.tag ? `refs/tags/${params.tag}` : `refs/heads/${params.branch || 'main'}`;\nconst out = execSync(`git ls-remote ${repoUrl} ${ref}`).toString();\nif (!out.trim()) throw new Error(`Ref not found in repo: ${ref}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify branch/tag existence with git ls-remote before triggering.","Ensure repos are not empty and default branch is set.","Keep CI variable branch names in sync with the remote."],"tags":["rest-api","git","ref-not-found","ci-cd","onedev"],"backgroundTag":"git-ref-not-found","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}