BitBucket 不更新 PR 的 refspec,导致 Jenkins 构建旧提交 [英] BitBucket does not update refspec for PR, causing Jenkins to build old commits

查看:26
本文介绍了BitBucket 不更新 PR 的 refspec,导致 Jenkins 构建旧提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 Git 的本地 BitBucket 服务器.我正在尝试开始使用持续集成,因此我设置了一个本地 Jenkins 实例.目标是让 Jenkins 检查拉取请求并构建项目,然后将结果报告给 BitBucket.

I am using a local BitBucket server with Git. I am trying to get started with Continous Integration so I've set up a local Jenkins instance. The goal is to have Jenkins check out pull-requests and build the project, and then report back to BitBucket with the result.

在 BitBucket 中,我使用 WebhookJenkins for Stash 每次创建/更新拉取请求时都会通知我的 Jenkins 实例.

In BitBucket I am using Webhook to Jenkins for Stash which notifies my Jenkins instance each time a pull-request is created/updated.

在 Jenkins 中,我使用 Stash pullrequest builder 插件当从上面的插件通知时,让 Jenkins 签出 pullrequest.我已经使用了文档中的设置,即

In Jenkins i am using Stash pullrequest builder plugin to have Jenkins checkout the pullrequest, when notified from the plugin above. I have used the settings in the documentation, i.e.

Refspec: +refs/pull-requests/*:refs/remotes/origin/pr/*
Branch Specifier: origin/pr/${pullRequestId}/from

它几乎可以工作......

It almost works...

当我在 BitBucket 中创建新的拉取请求时,Jenkins 得到通知,检查 PR 并将结果报告回 BitBucket.到现在为止还挺好.

When i create a new pull request in BitBucket, Jenkins get nofitied, checks out the PR and report the result back to BitBucket. So far so good.

但是,当我更新 PR(即提交新代码并推送到 BitBucket)时,Jenkins 会被触发,但仍会检查 PR 中的先前提交,而不是新提交.

However when I update the PR (i.e. commit new code and push to BitBucket), Jenkins gets triggered but still checks out the previous commit in the PR, and not the new commit.

我进行了一些调查,但被卡住了.据我了解 Refspec 指定我应该将 refs/remotes/origin/pr/* 映射到 refs/pull-requests/* 本地.但是,当我对现有 PR 进行新提交时,BitBucket 似乎不会更新 PR 的引用,这导致 Jenkins 只能找到旧的.

I've done some investegation but got stuck. From what I understand Refspec specifies that i should map refs/remotes/origin/pr/* to refs/pull-requests/* locally. However it does not seem like BitBucket updates the refs for the PR when i do a new commit to an existing PR, which causes Jenkins only to find the old one.

当我在提交并将更新推送到现有 PR 后运行 git ls-remote origin 时,我得到以下信息:

When I run git ls-remote origin after commiting and pushing an update to an existing PR i get this:

edf245 (new commit)...             refs/heads/feature/Name-Of-My-Branch-That-I-Created-Pull-Request-From-pr
af774f (previous commit in PR)...  refs/pull-requests/69/from
7fa82b (master)...                 refs/pull-requests/69/merge

然而,在访问 BitBucket 中的 PR 页面后,refs 似乎已更新,我得到以下结果:

However after visiting the PR-page in BitBucket, the refs seems to be updated and i get the following result:

edf245 (new commit)...             refs/heads/feature/Name-Of-My-Branch-That-I-Created-Pull-Request-From-pr
edf245 (new commit)...             refs/pull-requests/69/from
7fa82b (master)...                 refs/pull-requests/69/merge

如果我在此之后手动触发 Jenkins,它会构建最新的提交.

And if i manually trigger Jenkins after this it build the latest commit.

所以我的问题是,在我访问 BitBucket 中的实际 PR 页面之前,BitBucket 似乎并没有更新 refspec.我该如何解决这个问题?

So my problem is that BitBucket does not seem to upfate the refspec until I visit the acutal PR-page in BitBucket. How can i fix this?

谷歌搜索我最终发现的问题 here 似乎这种行为是设计使然...

Googling the problem I ended up here where it seems like the behaviour is by design...

推荐答案

请参阅 Daves 的回答,了解为什么会出现这个问题"以及为什么 Bitbucket 以这种方式设计.

See Daves answer for an explanation on why this "problem" arise and why Bitbucket is designed in this way.

但是我能够通过更改 Jenkins 插件中的设置来解决我的具体问题,以欺骗"Bitbucket 更新参考.

However i was able to solve my specific problem by changing the settings in the Jenkin-plugin, to "trick" Bitbucket into updating the refs.

通过在 Jenkins 中将选项 Build only if Stash 报告无冲突 设置为 true(在作业的 Build Trigger 下),您可以强制 Bitbucket 更新 refs,这意味着您将检查正确的提交

By setting the option Build only if Stash reports no conflicts to true in Jenkins (Under Build Trigger for the job), you force Bitbucket to update the refs which means you will check out the correct commit

参见 https://github.com/nemccarthy/stash-pullrequest-builder-plugin/issues/75 了解详情

这篇关于BitBucket 不更新 PR 的 refspec,导致 Jenkins 构建旧提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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