{"record":{"id":"5504caf735501ab2","repo":"theonedev/onedev","slug":"either-branch-or-tag-should-be-specified-but-not","errorCode":null,"errorMessage":"Either branch or tag should be specified, but not both","messagePattern":"Either branch or tag should be specified, but not both","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/TriggerJobResource.java","lineNumber":116,"sourceCode":"    private Long triggerJob(String projectPath, @Nullable String branch, @Nullable String tag, String job,\n\t\t\t\t\t\t\tString accessTokenValue, UriInfo uriInfo) {\n\t\tProject project = projectService.findByPath(projectPath);\n\t\tif (project == null)\n\t\t\tthrow new NotAcceptableException(\"Project not found: \" + projectPath);\n\n\t\tvar accessToken = accessTokenService.findByValue(accessTokenValue);\n\t\tif (accessToken == null)\n\t\t\tthrow new NotAcceptableException(\"Invalid access token\");\n\t\t\n\t\tvar subject = accessToken.asSubject();\n\t\tvar user = SecurityUtils.getUser(subject);\n\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)","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/TriggerJobResource.java#L98-L134","documentation":"triggerJob accepts an optional 'branch' and an optional 'tag' parameter to select the ref whose commit runs the job. Supplying both is ambiguous, so NotAcceptableException (406) is thrown when both are non-blank. The endpoint deliberately forbids the combination rather than picking one.","triggerScenarios":"GET/POST /~api/trigger-job with both branch and tag query parameters set to non-empty values, e.g. '?branch=main&tag=v1.0'.","commonSituations":"Templated CI scripts always appending branch while the caller also passes tag; merging two parameter lists; copying a URL and adding an extra parameter without removing the other.","solutions":["Remove either the branch or the tag parameter so exactly one is specified.","Parameterize your pipeline so the ref kind (branch vs tag) decides which parameter is sent.","If you truly need both refs, trigger the job twice, once per ref."],"exampleFix":"// before\ncurl 'http://onedev/~api/trigger-job?project=p&job=CI&branch=main&tag=v1.0'\n// after\ncurl 'http://onedev/~api/trigger-job?project=p&job=CI&tag=v1.0'","handlingStrategy":"validation","validationCode":"if (params.branch?.trim() && params.tag?.trim())\n  throw new Error('Specify either branch or tag, not both');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide the ref kind once in your pipeline template and forward only that parameter.","When merging parameter maps, filter out defaults that conflict."],"tags":["rest-api","query-parameters","ci-cd","onedev"],"backgroundTag":"mutually-exclusive-options","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"}