Git PullRequest 作业失败。找不到任何要构建的修订版。验证此作业的存储库和分支配置

问题描述 投票:0回答:12

昨天我的 pullrequest 作业失败,输出如下:

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.

我进行了调查,发现属性 ${sha1} 中什么也没有。当我将绝对路径粘贴到拉取请求构建器(如 pr/341/merge)而不是 ${sha1} 时,构建可以正常工作。它可能是什么?

Git 客户端插件 1.9.0

GitHub API 插件 1.44

git jenkins pull-request
12个回答
58
投票

我在这上面花了很长时间。上面的评论“如果我将此字段留空”就像一个魅力。在供应链管理中:
1)选择Git
2)姓名:

origin

3) 参考规格:
+refs/pull/*:refs/remotes/origin/pr/*

4)要建立的分支:留空

这解决了上述错误。


38
投票

根据this,Github分支的默认名称已从“master”更改为“main”。

因此,在为新存储库创建新作业时,必须将“main”设置为分支名称,而不是“master”。

请注意,github 可以将“master”(或您方便的任何其他名称)设置为默认分支名称。


14
投票

您需要定义分支名称,因为 Jenkins 默认捕获 master,而 GitHub 中没有 master,它现在是 main,因此对于 GitHub,您还需要传递分支名称。

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

它解决了我的问题


12
投票

我也浪费了一些时间寻找解决方案。一段时间后,我了解到分支名称不同,这就是它不被采用的原因。

解决方案在我的存储库中是主要的,并尝试与 master.it 错误

像这里一样改变


10
投票

此处所述,如果您想手动构建作业,请在作业设置中检查此构建是参数化,并添加名为

sha1
的字符串参数,默认值为
master
。开始构建时,给出您想要构建的 sha1 参数提交 ID 或引用名称(例如:origin/pr/9/head)。


8
投票

我通过使用“要构建的分支 - 分支说明符”中的 refs/heads/<branchName>

 语法修复了相同的错误消息

例如,我将

origin/master

 作为分支说明符来修复此作业,而不是 
refs/remotes/origin/master

(就我而言,我不确定是什么导致出现此错误消息,因为该作业之前仅使用

origin/master

 作为分支说明符就可以正常工作。可能是相关更新或配置更改...) 


请注意,您可以使用

git show-ref

 命令列出本地存储库中的引用,例如

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

还有,“?” “分支说明符”字段旁边的帮助文档也支持此答案作为指定分支说明符以确保预期分支明确的最安全选项:

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.
    

3
投票
这对我有用:

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

2
投票
经过大量研究和绞尽脑汁。我收到了同样的错误,我发现如果您使用不同的 git 路径也会发生此错误。确保您有正确的路径。例如: 我将

C:\Program Files\Git\git-bash.exe 替换为 C:\Program Files\Git in\git.exe ,这解决了问题。


2
投票
有时如果“分支说明符”设置不正确,就会发生这种情况。 我更正了说明符,它对我有用。

*/release/release4.5.0

*/feature/myfeature
    

1
投票
我最近遇到了同样的错误,并且以上方法都不适合我,因为我希望 Jenkins 签出我的代码的特定分支。分支名称设置为

${BRANCH},这是我在同一作业中创建的 Jenkins 参数。

如果我使用其他分支,效果很好。我花了很长时间来调试,因为它在其他地方都有效。我可以克隆存储库并在本地自行签出该分支,不会出现任何问题。但似乎只有 Jenkins 报告了这个错误。

最后,经过大量调查,我意识到我在此 Jenkins 作业中设置的 BRANCH 参数的默认值是我从参数部分的同一作业的早期运行中复制的。如果我们从该部分复制,看起来会添加一个隐藏的特殊字符,这就是为什么即使它看起来是我想在 Jenkins 日志中签出的同一个分支,但它不知何故有一个额外的隐藏字符,因此每次都失败。我从该参数中删除了默认值,并在作业配置中手动重新输入该值作为默认值,之后工作正常。


1
投票
我指定分支为主

Branch as main

添加 git 路径并解决问题

git path


0
投票
我遇到了同样的问题,花了4个小时,但终于解决了。

就我而言,错误是由于错误的 Git exe 造成的。在Jenkins内部,在Windows上设置Git exe路径时,设置cmd文件夹下的路径

就我而言,它是 C:\Program Files\Gi
© www.soinside.com 2019 - 2024. All rights reserved.