theonedev/onedev · error · NotAcceptableException

Either branch or tag should be specified, but not both

Error message

Either branch or tag should be specified, but not both

What it means

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.

Source

Thrown at server-core/src/main/java/io/onedev/server/rest/resource/TriggerJobResource.java:116

    private Long triggerJob(String projectPath, @Nullable String branch, @Nullable String tag, String job,
							String accessTokenValue, UriInfo uriInfo) {
		Project project = projectService.findByPath(projectPath);
		if (project == null)
			throw new NotAcceptableException("Project not found: " + projectPath);

		var accessToken = accessTokenService.findByValue(accessTokenValue);
		if (accessToken == null)
			throw new NotAcceptableException("Invalid access token");
		
		var subject = accessToken.asSubject();
		var user = SecurityUtils.getUser(subject);
		ThreadContext.bind(subject);
		try {
			if (!SecurityUtils.canRunJob(subject, project, job))		
				throw new UnauthorizedException();

			if (StringUtils.isNotBlank(branch) && StringUtils.isNotBlank(tag)) 
				throw new NotAcceptableException("Either branch or tag should be specified, but not both");
			
			String refName;
			if (branch != null)
				refName = GitUtils.branch2ref(branch);
			else if (tag != null)
				refName = GitUtils.tag2ref(tag);
			else
				refName = GitUtils.branch2ref(project.getDefaultBranch());
			
			RevCommit commit = project.getRevCommit(refName, false);
			if (commit == null)
				throw new NotAcceptableException("Ref not found: " + refName);
			
			Map<String, List<String>> jobParams = new HashMap<>();
			for (Map.Entry<String, List<String>> entry: uriInfo.getQueryParameters().entrySet()) {
				if (!entry.getKey().equals(PARAM_PROJECT) && !entry.getKey().equals(PARAM_BRANCH)
						&& !entry.getKey().equals(PARAM_TAG) && !entry.getKey().equals(PARAM_JOB) 
						&& !entry.getKey().equals(PARAM_ACCESS_TOKEN)

View on GitHub (pinned to d44925c47c)

Solutions

  1. Remove either the branch or the tag parameter so exactly one is specified.
  2. Parameterize your pipeline so the ref kind (branch vs tag) decides which parameter is sent.
  3. If you truly need both refs, trigger the job twice, once per ref.

Example fix

// before
curl 'http://onedev/~api/trigger-job?project=p&job=CI&branch=main&tag=v1.0'
// after
curl 'http://onedev/~api/trigger-job?project=p&job=CI&tag=v1.0'
Defensive patterns

Strategy: validation

Validate before calling

if (params.branch?.trim() && params.tag?.trim())
  throw new Error('Specify either branch or tag, not both');

Prevention

When it happens

Trigger: GET/POST /~api/trigger-job with both branch and tag query parameters set to non-empty values, e.g. '?branch=main&tag=v1.0'.

Common situations: 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.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/5504caf735501ab2. Report an issue: GitHub.