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

25

71

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

Siliceous answered 28/5, 2014 at 8:24 Comment(1)
I am here after github made main the default branch instead of masterGradus
T
58

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.

Thalia answered 1/4, 2016 at 15:4 Comment(4)
please, edit your answer and add code/commands formatting for the ease of read. thank you.Eunuchize
Thanks for the hint about leaving empty the branches to build. Unfortunately in my small example I still needed to manually configure the merge of the master branch into the PR branch (at least when working with branches not forks): https://mcmap.net/q/276382/-jenkins-build-fail-for-pr-from-githubChantry
The above comment "if I leave this field blank"? What comment? Where?Kutzenco
** I too faced the same problem in Jenkins, I removed the branch name to build, My problem got fixed ** I struggled for more than 2 hoursOrmsby
B
44

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.

Boneyard answered 26/10, 2020 at 6:39 Comment(1)
Perfect answer. It worked for me. Thanks.Gainer
R
16

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

Rooftree answered 18/6, 2021 at 10:3 Comment(0)
D
16

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

enter image description here

Changed like here

enter image description here

Docile answered 21/11, 2021 at 7:44 Comment(1)
with same err with me branch name not found.Luminiferous
G
10

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

Grant answered 27/7, 2014 at 17:47 Comment(0)
S
8

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, e.g.

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.
Skutchan answered 18/6, 2018 at 16:30 Comment(3)
where do you define "Branches to build - branch specifier" is this in your pipeline when you call SCM or you do it in jenkins?Unarm
@MiguelCosta In Jenkins. I see this in Jenkins -> Select a job -> Configure -> Source Code Management -> Branches to build -> Branch SpecifierSkutchan
thanks for the feedback, I'm using a multi branch pipeline and I search and I could not find anything like that, maybe I'm using a different jenkins version or it's not active on my infrastructure, anyway thank youUnarm
O
3

this worked for me:

stage ('Git Checkout') {
  steps {
      git branch: 'main', url: 'https://<token>@github.com/username/repoName.git'
     }
  }
Onomatopoeia answered 22/10, 2021 at 20:28 Comment(0)
C
2

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
Chock answered 22/8, 2016 at 5:55 Comment(0)
M
2

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.

Monazite answered 26/10, 2017 at 13:4 Comment(0)
P
1

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.

Premonish answered 22/7, 2020 at 2:34 Comment(0)
D
1

I specified Branch as main

Branch as main

and git path added and solved the issue git path

Docket answered 27/7, 2022 at 18:32 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Jannette
I
1

Make sure the branch you specify in the Branch Specifier field is remote.

Open the project repository in your Bitbucket/GitHub/etc. and search your branch name in the branches.

If you can't find it, open a cmd where your branch is checked out, save/update/stash/remove any changes you have and push the branch to the remote origin:

git push --set-upstream origin <your_branch_name>.

Intima answered 6/3 at 9:31 Comment(1)
I edited the comment. Hope it is better now. Thanks.Intima
R
0

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.

Renee answered 26/6, 2018 at 12:35 Comment(0)
F
0

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.

Furore answered 14/11, 2019 at 5:3 Comment(0)
U
0

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.

Unipersonal answered 14/2, 2020 at 7:34 Comment(0)
V
0

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.

Vole answered 6/10, 2020 at 12:15 Comment(0)
T
0

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.

Typhus answered 4/2, 2021 at 12:34 Comment(0)
A
0

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.

  • e.g.
origin/feature/branch_name
Autostability answered 9/2, 2021 at 11:28 Comment(0)
T
0

Leaving blank in Branch Specifier in Jenkins worked for me SourceCodeManagement>Branchs to build>Branch Specifier it would be defaulted to */master remove the defaulted one

Tollefson answered 2/3, 2021 at 6:45 Comment(0)
K
0

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 )

Karyn answered 8/5, 2021 at 8:13 Comment(1)
You might want to edit your answer a bit to give it more structure and become more readable. In the current version it looks like stream-of-conciousnessTook
H
0

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.

Hite answered 31/7, 2021 at 5:54 Comment(0)
O
0

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

Oberg answered 6/5, 2022 at 11:11 Comment(0)
Q
0

Try to specify the branch name exactly as it is instead of representing in {}

Quixotic answered 14/12, 2023 at 11:0 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Jannette
R
0

In my case, this happened because I wrote and incorrect branch name. As soon as I noticed that the job could run correctly again.

Rampant answered 13/2 at 19:4 Comment(0)
M
0

I did all the things suggested by everyone on this post with regards to the changing the master branch to main branch but it did not work for me.

what worked for me was changing my cicd pipeline code itself. This is what i changed and specified the main branch here itself:-

stage('Checkout') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/rajrules21/Jenkins-Projects']]])
                //git 'https://github.com/rajrules21/Jenkins-Projects'
            }
Marci answered 15/2 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.