Jenkins Pull Request构建器忽略$ {sha1}的分支 [英] Jenkins Pull Request builder ignoring branches with ${sha1}

查看:487
本文介绍了Jenkins Pull Request构建器忽略$ {sha1}的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置



轮询结果依然存在:





我知道这个错误导致了这个问题,但从1.31更新到1.33后,问题仍然存在。



我已阅读有关运行两个进程的信息,但我不确定为什么需要它(请解释,如果有的话)。



可以在我的配置中看到任何错误?任何澄清或建议将是最受欢迎的。

干杯 -

解决方案

看起来,基于 + refs / pull / *:refs / remotes / origin / pr / * 的refspec,您希望此项目建立拉取请求只有



但是,您似乎已经启用了Poll SCM触发器以及Github Pull Request Builder(GHPRB)触发器。

请记住,GHPRB插件已经是触发器了。启用其他触发器的唯一原因是,如果您希望此项目建立正常分支。



所以第一步是为了解决这个问题。确保启用的唯一触发器是GHPRB插件。



下一步是识别您没有使用Github webhooks - 可能是由于防火墙的限制。这意味着您正在使用一个cronjob,它将使用Github API来检查Pull Request更新并将其与最后一次轮询进行比较以检测更改。



这意味着您的凭证首先必须是正确的。您可以在GHPRB插件部分下的Jenkins的系统设置部分(您必须是管理员)中检查凭证。确保凭证具有查看,评论等所需的所有权利。



如果所有这些都是正确的,日志可能会提供更多信息。如果您是管理员,则可以转至管理詹金斯并查找系统日志。通过查看日志,您可能会发现与您的问题相关的错误。



在您的情况下,因为我是您的系统管理员,并且正在输入所有这些可能来的第三方的好处,我注意到当它试图访问API时,我们看到FileNotFound异常从GitHub插件抛出。



原因?



GHPRB插件使用Github插件与API进行通信,因此轮询Pull Requests。 Github插件的 Project url 字段用于为轮询请求生成API URL。



删除URL中的 .git 部分!即使在浏览器中访问URL时完美找到,如果添加 .git 后缀添加到API中的项目名称中,它会生气并给你一个 404 。通过从 Project url 字段中删除该后缀,GitHub插件将为API请求解析正确的URL路径,并且生活很好。



构建PR和正常分支



为了在Pull Request和普通分支中使用单个Jenkins项目,需要做一些额外的事情。


  1. 为其他分支启用触发器,例如GitHub钩子或SCM轮询

  2. 更新 refspec 配置,使其不仅包含您当前配置的pull request refspec,还包含您希望构建的分支的refspec(s) 。例如,如果您希望所有标签和分支都可用于构建,您可以使用 + refs / pull / *:refs / remotes / origin / pr / * + refs / heads / *:refs /因为分支说明符通常设置为 $ {sha1} ,因此建筑物除非构建由GHPRB插件触发,否则PR和此环境变量不会创建,您需要将此项目转换为Parametarized Build并创建一个名为 sha1 ,如果您不使用GHPRB插件,则默认值等于您通常在Branch Specifier下放置的分支,然后确保Branch Specifier字段引用 $ {sha1} 变量。如果GHPRB插件用于触发构建,它将覆盖此参数,否则默认值将用于其他触发器。这也使您有机会通过在构建时从UI(或脚本)指定参数来手动运行构建。

你可能需要做一些其他的调整,但那些是立即想到的主要内容。


I'm attempting to set up the Jenkins PR builder plugin to hit github on new pull request. I've followed along with the docs, and have tried "many" different configurations, but I can't seem to get past this:

"Ignoring refs/heads/jenkins_testing as it doesn't match any of the configured refspecs"

If I leave the branch specifier empty, "any" change on a PR does fire a build. From this, I know

  • the github repo is getting found
  • credentials are good
  • I'm polling, instead of using hooks, and that is working
  • the refspec is at least "close" to appropriate
  • notifications are showing up in slack

Refspec : I'm using the prescribed settings for PRs only -

+refs/pull/*:refs/remotes/origin/pr/*

Branches I've tried a number of settings

${sha1}                  - ignored 
${ghprbActualCommit}     - ignored
branch-id                - gets built, but I need "any" PR
** (blank)               - too much gets built, undesirable

Jenkins / PR builder config :

Results of polling persist:

I am aware of this bug that causes exactly this issue, but after updating from 1.31 to 1.33, the issue persists.

I have read about running two processes, but I'm not sure why I'd need that (please explain, if that would have ).

Can you see anything wrong in my config? Any clarification or advice would be most welcome.

Cheers -

解决方案

It appears, based on the refspec of +refs/pull/*:refs/remotes/origin/pr/* that you want this project to build pull requests only.

However, it seems that you have the Poll SCM trigger enabled along with the Github Pull Request Builder (GHPRB) trigger.

Remember, the GHPRB plugin is already a trigger. The only reason to enable additional triggers would be if you want to have this project also build normal branches. If this is the case, please see the bottom of this post for some more information about this use-case.

So step one is to make sure that the only trigger enabled is the GHPRB plugin.

The next step is to recognize that you are not using Github webhooks - likely due to firewall constraints. This means you are using a cronjob that will use the Github API to check for Pull Request updates and compare it to the last poll to detect changes.

This means that your credentials must be correct, first of all. You can check the credentials in the System Settings portion of Jenkins (you must be an Admin) under the GHPRB plugin section. Make sure the credentials have all the rights needed to view, comment, etc. your repository.

If all of that is correct, the logs will likely give you more information. If you are an admin, you can go to Manage Jenkins and find System Log. By viewing the log, you'll likely find errors that are related to your problem.

In your case, since I'm your sysadmin and am typing all of this for the benefit of a 3rd party who may come by, I noticed that we were seeing FileNotFound exceptions being thrown from the GitHub plugin when it attempted to access the API.

The cause?

The GHPRB plugin uses the Github plugin to communicate with the API and, thus, poll for Pull Requests. The Project url field of the Github Plugin is used to generate the API URLs for the poll requests.

Remove the .git portion of the URL! Even though it will work perfectly find when going to the URL in your browser, if you add the .git suffix to the project name in the API it gets angry and will give you a 404. By removing this suffix from the Project url field, the GitHub plugin will parse the correct URL path for the API requests and life is good.

Building PRs and Normal Branches

In order to use a single Jenkins project for both Pull Requests and normal branches, you need to do a few extra things.

  1. Enable a trigger for the other branches such as GitHub hooks or SCM Polling
  2. Update the refspec configuration to include not only the pull request refspec you have configured currently, but also the refspec(s) of the branches you wish to be built. For example, if you wanted all tags and branches to be available for building, you would use +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/*
  3. Because the branch specifier is normally set to ${sha1} for building PRs and this environment variable is not created unless the build is triggered by the GHPRB plugin, you will want convert this project into a Parametarized Build and create a parameter called sha1 with a default value equal to the branch(es) you would normally have put under Branch Specifier if you weren't using the GHPRB plugin, and then ensure that the Branch Specifier field references the ${sha1} variable. The GHPRB plugin will override this parameter if it is used to trigger the build, otherwise the default value will be used for other triggers. This also gives you a chance to manually run builds by specifying the parameter from the UI (or a script) at build-time.

You may need a few other tweaks, but those are the main ones that come to mind immediately.

这篇关于Jenkins Pull Request构建器忽略$ {sha1}的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆