Jenkins Pull Request builder 忽略带有 ${sha1} 的分支 [英] Jenkins Pull Request builder ignoring branches with ${sha1}

查看:12
本文介绍了Jenkins Pull Request builder 忽略带有 ${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 检查拉取请求更新并将其与上次轮询进行比较以检测更改.

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

如果所有这些都正确,日志可能会为您提供更多信息.如果你是管理员,你可以去管理 Jenkins 并找到系统日志.通过查看日志,您可能会发现与您的问题相关的错误.

在您的情况下,由于我是您的系统管理员并且正在输入所有这些内容是为了可能会出现的第 3 方的利益,我注意到我们看到 GitHub 插件在尝试访问时抛出 FileNotFound 异常API.

原因?

GHPRB 插件使用 Github 插件与 API 通信,从而轮询拉取请求.Github 插件的 Project url 字段用于生成投票请求的 API URL.

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

建立 PR 和普通分支

为了将单个 Jenkins 项目同时用于拉取请求和普通分支,您需要做一些额外的事情.

  1. 为其他分支启用触发器,例如 GitHub 挂钩或 SCM 轮询
  2. 更新 refspec 配置,不仅包括您当前配置的拉取请求 refspec,还包括您希望构建的分支的 refspec.例如,如果您希望所有标签和分支都可用于构建,您将使用 +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/*
  3. 因为分支说明符通常设置为 ${sha1} 用于构建 PR,并且除非由 GHPRB 插件触发构建,否则不会创建此环境变量,您将希望将此项目转换为参数化构建并创建一个名为 sha1 的参数,其默认值等于如果您不使用 GHPRB 插件,您通常会放在分支说明符下的分支,然后确保分支说明符字段引用 ${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 builder 忽略带有 ${sha1} 的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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