theonedev/onedev · error · NotAcceptableException

Ref not found: ${refName}

Error message

Ref not found: ${refName}

What it means

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.

Source

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

		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)
						&& !entry.getKey().equals(PARAM_REBUILD_IF_FINISHED)) {
					jobParams.put(entry.getKey(), entry.getValue());
				}
			}
			
			var build = jobService.submit(user, project, commit.copy(), job, jobParams, refName, 
			null, null, "Triggered via restful api");
			if (build.isFinished())
				jobService.resubmit(user, build, "Rebuild via restful api");
			return build.getId();
		} finally {
			ThreadContext.unbindSubject();

View on GitHub (pinned to d44925c47c)

Solutions

  1. Verify the branch/tag exists in the repository (git ls-remote) and fix the parameter value.
  2. Push the branch/tag, or set the project's default branch correctly if triggering without branch/tag.
  3. If the repo is empty, make an initial commit before triggering jobs.

Example fix

// before
curl 'http://onedev/~api/trigger-job?project=p&job=CI&branch=mian&access_token=T'
// after (branch exists)
git push origin main
curl 'http://onedev/~api/trigger-job?project=p&job=CI&branch=main&access_token=T'
Defensive patterns

Strategy: validation

Validate before calling

const ref = params.tag ? `refs/tags/${params.tag}` : `refs/heads/${params.branch || 'main'}`;
const out = execSync(`git ls-remote ${repoUrl} ${ref}`).toString();
if (!out.trim()) throw new Error(`Ref not found in repo: ${ref}`);

Prevention

When it happens

Trigger: 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).

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

Related errors


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