简体   繁体   中英

Git PullRequest job failed. Couldn't find any revision to build. Verify the repository and branch configuration for this job

Yesterday my pullrequest jobs failed with the following output:

11:07:41  > git rev-parse origin/${sha1}^{commit}
11:07:41  > git rev-parse ${sha1}^{commit}
11:07:41 ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.

I have made an investigation and saw that in property ${sha1} there was nothing. When i paste an absolute path to pull request builder like pr/341/merge instead of ${sha1} the build works. What it can be?

Git Client Plugin 1.9.0

GitHub API Plugin 1.44

I spent a long time on this. The above comment "if I leave this field blank" worked like a charm. In SCM:
1) select Git
2) Name: origin
3) Refspec: +refs/pull/*:refs/remotes/origin/pr/*
4) Branches to build : leave blank

This solved the above error.

According to this , Github branch's default name have been changed from "master" to "main".

So, when creating new jobs for a new repository, you have to set "main" as the branch name instead of "master".

Note that github has way to set "master" (or any other name of your convenience) as default branch name.

As stated here , If you want to manually build the job, in the job setting check This build is parameterized and add string parameter named sha1 with a default value of master . When starting build give the sha1 parameter commit id you want to build or refname (eg: origin/pr/9/head).

I fixed this same error message by using the refs/heads/<branchName> syntax in the "Branches to build - branch specifier" .

For example, instead of origin/master , I put refs/remotes/origin/master as the branch specifier to fix the job.

(In my case, I'm not sure what caused this error message to appear, as the job was previously working fine with just origin/master as the branch specifier. It may have been a related update or configuration change...)


Note that you can use git show-ref command to list references in a local repository, eg

git show-ref master
28f1f186807d1316bf1c59631d6d8825a5087e27 refs/heads/master
28f1f186807d1316bf1c59631d6d8825a5087e27 refs/remotes/origin/master

Also, the "?" help documentation next to 'Branch Specifier' field also supports this answer as the safest option for specifying the branch specifier to make sure the expected branch is unambiguous:

Specify the branches if you'd like to track a specific branch in a repository. If left blank, all branches will be examined for changes and built.

The safest way is to use the refs/heads/<branchName> syntax. This way the expected branch is unambiguous.

Possible options:

<branchName>
Tracks/checks out the specified branch. If ambiguous the first result is taken, which is not necessarily the expected one. Better use refs/heads/<branchName>.
E.g. master, feature1,...

refs/heads/<branchName>
Tracks/checks out the specified branch.
E.g. refs/heads/master, refs/heads/feature1/master,...

<remoteRepoName>/<branchName>
Tracks/checks out the specified branch. If ambiguous the first result is taken, which is not necessarily the expected one.
Better use refs/heads/<branchName>.
E.g. origin/master

remotes/<remoteRepoName>/<branchName>
Tracks/checks out the specified branch.
E.g. remotes/origin/master

refs/remotes/<remoteRepoName>/<branchName>
Tracks/checks out the specified branch.
E.g. refs/remotes/origin/master

<tagName>
This does not work since the tag will not be recognized as tag.
Use refs/tags/<tagName> instead.
E.g. git-2.3.0

refs/tags/<tagName>
Tracks/checks out the specified tag.
E.g. refs/tags/git-2.3.0

<commitId>
Checks out the specified commit.
E.g. 5062ac843f2b947733e6a3b105977056821bd352, 5062ac84, ...

${ENV_VARIABLE}
It is also possible to use environment variables. In this case the variables are evaluated and the result is used as described above.
E.g. ${TREEISH}, refs/tags/${TAGNAME},...

<Wildcards>
The syntax is of the form: REPOSITORYNAME/BRANCH. In addition, BRANCH is recognized as a shorthand of */BRANCH, '*' is recognized as a wildcard, and '**' is recognized as wildcard that includes the separator '/'. Therefore, origin/branches* would match origin/branches-foo but not origin/branches/foo, while origin/branches** would match both origin/branches-foo and origin/branches/foo.

:<regular expression>
The syntax is of the form: :regexp. Regular expression syntax in branches to build will only build those branches whose names match the regular expression.

You need to define branch name because Jenkins catches master by default and there is no master in GitHub, it's now main so in the case of GitHub you need to pass branch name also.

git branch: 'main', credentialsId: 'GithubCred', url: 'Your-Repo-URL'

It resolved my issue

sometimes this happens if "Branch Specifier" is not set properly. I corrected specifier and it worked for me.

*/release/release4.5.0

or

*/feature/myfeature

After lots of research and head breaking. I was receiving the same error and I found out that this error also occurs if you are using a different git path. Make sure you have the correct path. For ex: I replaced C:\\Program Files\\Git\\git-bash.exe with C:\\Program Files\\Git\\bin\\git.exe and this resolved the issue.

I came across the same issue and spent 4 hours into it but finally got it resolved.

In my case, error was because of wrong Git exe. Inside Jenkins, while setting Git exe path on windows, set the path under cmd folder

In my case it was C:\\Program Files\\Git\\cmd\\git.exe

It resolved my issue.

I had the same problem. TIn my case, the cause was that I used a github repository that was a mirror of an svn repository (because svn is not properly supported by SonarCloud). The default in Jenkins was */master . The solution ( found by Gavin McDonald of Apache INFRA ) was to use */trunk . Another problem is the ".git" in the URL, that should not be used.

Whenever we don't specify a correct branch to pull, the git will look for all the branches that repository has and end up throwing an error saying "Couldn't find any revision to build. Verify the repository and branch configuration for this job."

I had faced the same issue with my git pull and i was using jenkins to specify the configuration.

If we leave it to blank, it would get the files from master branch, but if something is wrong or a typo is there, it would look for all branches and throw error saying branch not found.

I was facing this same error recently and none of the above were working for me since I wanted Jenkins to checkout a specific branch of my code. The branch name was set to ${BRANCH} which was a Jenkins parameter I created on same job.

If I used some other branch, it worked fine. Took me a long time to debug since it worked everywhere else. I could clone the repo and checkout that branch myself locally without issues. But only Jenkins seemed to be reporting this error.

Finally after a lot of investigation, I realised the default value that I set to the BRANCH parameter in this Jenkins job was copied by me from an earlier run of the same job from the Parameters section. Looks like a hidden special character gets added if we copy from that section and that is why even though it looked to be the same branch I wanted to checkout in the Jenkins logs, it was somehow having an additional hidden character and hence was failing each time. I deleted the default value from that parameter and re-typed that value as the default manually in the Job configuration and it worked fine after that.

Sometimes the branch name specified in the jenkins and repository are different. In my case jenkins set Master as a default branch in jenkins. But my actual branch is main. Which costs me over two hours of my time to identify. I didn't change it as jenkins sets it default. Errormain But it is the error. So first verify the branch name in your repository and the branch name in jenkins if you get this error.

On your Jenkins' job configuration, under the Pipeline SCM section, uncheck "Lightweight checkout" and Save. Also make sure you name your branch correctly, as others have mentioned.

I faced similar issue, the error was in the branch name , you'll need to specify the origin repository in the branch name to make sure changes are picked up.

  • eg
origin/feature/branch_name

在 Jenkins 的 Branch Specifier 中留空对我有用 SourceCodeManagement>Branchs to build>Branch Specifier 它将默认为 */master 删除默认的

Question - ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job. Hi Guys Kindly check the branch name that is targetting from jenkins build from It should be same both side(git and jenkins )

In my case I resolved the issue by updating Jenkins Default branch name from " /master" to " /Master". I am using Bitbucket cloud and Master branch.

this worked for me:

stage ('Git Checkout') {
  steps {
      git branch: 'main', url: 'https://<token>@github.com/username/repoName.git'
     }
  }

I also waste some time finding a solution. After some time I understood branch names are different that's why it's not taking.

The solution is in my repo is main and trying with the master.its the error

在此处输入图片说明

Changed like here

在此处输入图片说明

In my case, below two values were missing. Inside Pipeline ==> Definition ==> SCM ==> Advanced ==>

Name = origin

Refspec = +refs/pull/${ghprbPullId}/*:refs/remotes/origin/pr/${ghprbPullId}/*

I was using ${ghprbActualCommit} In Branch Specifier (blank for 'any') field

I specified Branch as main

Branch as main

and git path added and solved the issue git path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM