jenkinsgithub拉请求build设者选错了提交

我正在使用插件的GitHub拉请求生成器jenkins。 然后,我build立了从GitHub的webhooks,当一个新的合并请求打开或提交时触发jenkins中的构build。

我用Jenkins DSLconfiguration了GHPRB插件:

job("name") { properties { githubProjectUrl("https://github.com/org/${repo}") } scm { git { remote { name("origin") url("[email protected]:org/${repo}.git") credentials("jenkins-ssh-keyid") } branch("**") extensions { gitTagMessageExtension() } } } triggers { githubPullRequest{ admins(["github-username"]) orgWhitelist('org-name') cron("") triggerPhrase("build") extensions { commitStatus { context("unittest") } } useGitHubHooks() } } steps { shell("./run-unittests"); } } 

我遇到的问题是Jenkins有时候会感到困惑,并select错误的提交方式来构build。

当发生这种情况时,jenkins输出如下所示:

 GitHub pull request #9 of commit 126434b, no merge conflicts. Setting status of 126434b to PENDING with url http://jenkins/job/unittest/26/ and message: 'Build started sha1 is merged.' Using context: unittest > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url [email protected]:org/repo.git # timeout=10 Fetching upstream changes from [email protected]:org/repo.git > git --version # timeout=10 using GIT_SSH to set credentials > git -c core.askpass=true fetch --tags --progress [email protected]:org/repo.git +refs/heads/*:refs/remotes/origin/* Seen branch in repository origin/feature-branch-0 Seen branch in repository origin/feature-branch-1 Seen branch in repository origin/feature-branch-2 Seen 3 remote branches Checking out Revision 1995d66 (origin/master) 

在这里,jenkins从使用function分支的尖端( 1995d66 )转而使用主控( 1995d66 )的尖端。

  > git config core.sparsecheckout # timeout=10 > git checkout -f 1995d66 > git rev-list ba7ec55 # timeout=10 > git describe --tags 126434b # timeout=10 Tag information could not be determined for this revision; no git tag info will be exported 

请注意,当Git标记消息插件运行git describe来检查标记信息时,它正在使用特性分支的提交ID。

jenkins然后继续工作,工作的主要提示( 1995d66 ),而不是function分支提示( 126434b )按预期。

问题是branch规范和refspec 。 更改工作的scm.git部分,解决了Jenkins检查错误提交的问题:

 scm { git { remote { name("origin") url("[email protected]:org/${repo}.git") credentials("jenkins-ssh-keyid") refspec('+refs/pull/*:refs/remotes/origin/pr/*') } branch('${ghprbActualCommit}') } } }