3

我有一个GitChangeSet对象(最终来自构建)。我想找到与该提交关联的存储库名称或 URL。但是,该对象的任何属性似乎都没有暗示此提交最终来自何处。例如:

affectedFiles=[hudson.plugins.git.GitChangeSet$Path@2a7ac0cb, hudson.plugins.git.GitChangeSet$Path@1d9fb12a, hudson.plugins.git.GitChangeSet$Path@3b47e461, hudson.plugins.git.GitChangeSet$Path@35be1e86]
comment=CF-703 - remove testing-only hostsfile entry that caused "hostname -f"
to return "localhost"

date=2017-12-19 16:25:17 -0700
id=cfc01dfbf1015496074c2c1e6c9663cfb0f49751
commitId=cfc01dfbf1015496074c2c1e6c9663cfb0f49751
branch=null
msgEscaped=CF-703 - remove testing-only hostsfile entry that caused "hostname -f"
timestamp=1513725917000
authorName=hendrenj
parentCommit=bf4b919e74c635c61c4761134d6b53445829593d
msg=CF-703 - remove testing-only hostsfile entry that caused "hostname -f"
class=class hudson.plugins.git.GitChangeSet
msgAnnotated=CF-703 - remove testing-only hostsfile entry that caused "hostname -f"
commentAnnotated=CF-703 - remove testing-only hostsfile entry that caused &quot;hostname -f&quot;<br>to return &quot;localhost&quot;<br>
revision=cfc01dfbf1015496074c2c1e6c9663cfb0f49751
paths=[hudson.plugins.git.GitChangeSet$Path@2a7ac0cb, hudson.plugins.git.GitChangeSet$Path@1d9fb12a, hudson.plugins.git.GitChangeSet$Path@3b47e461, hudson.plugins.git.GitChangeSet$Path@35be1e86]
createAccountBasedOnEmail=false
affectedPaths=[recipes/default_vhost.rb, metadata.rb, test/integration/shared/serverspec/default_vhost/default_vhost.rb, Policyfile.lock.json]
authorEmail=*******@*******.***
parent=hudson.plugins.git.GitChangeSetList@2eb9acad
author=Jay Hendren

我通过迭代得到了这个提交对象build.changeSets(我相信它来自类hudson.model.AbstractBuild)。我确实知道这个特定的提交来自一个全局共享库存储库,而不是与这个构建关联的主存储库,但我没有看到任何明显的方式来以编程方式提取该信息。 如何以编程方式确定GitChangeSet对象(或一般其他对象hudson.model.AbstractBuild.changeSets)来自哪个存储库?


作为上下文,我正在为失败的构建开发一个电子邮件报告,其中收集与失败的构建相关的提交列表。由于我的作业之间存在复杂的上游/下游关系,一个存储库中的提交可能会触发一系列构建,因为成功的构建会触发依赖上游作业的下游作业。此外,还有其他与我的构建相关的存储库,特别是全局共享库存储库。我希望我的报告提及最终导致当前版本的一系列构建的提交。到目前为止,找到这些上游提交并没有太痛苦(感谢UpstreamJobCause),但我已经挂断了确定这些提交最终来自哪里。如果您不知道我的问题的答案,我将不胜感激评论中有关此问题的替代方法的任何建议。

4

3 回答 3

2

用于getChangeSetLink为您构建 URL。通过这种方式,您不需要对 URL 的任何部分进行硬编码。

build.changeSets.each { changeSetList ->
  def browser = changeSetList.browser
  changeSetList.items.each { changeSet -> 
    println browser.getChangeSetLink(changeSet)
  }
}
于 2019-11-04T07:50:06.020 回答
0

您可以使用以下代码获取提交 url,该代码可以在 jenkins 脚本控制台中进行测试

// Jenkins
//  .instance
//  .getItem('JobName')
//  .getBuild('buildnumber')
build
 .changeSets.each{ changeSetList ->
   changeSetList.items.each{ changeSet -> 
     println "${changeSetList.browser.repoUrl}commit/${changeSet.commitId}"
   }
 }
于 2018-10-26T13:26:50.353 回答
0

这有时可以解决问题 - 给定一个GitChangeSet名为的对象commit

commit.getParent().getBrowser().getRepoUrl()

存储库URL 附加到 的实例hudson.plugins.git.browser.GitRepositoryBrowser,因此您的作业配置必须为存储库源设置浏览器才能使其正常工作(默认的“自动检测浏览器”选项通常效果很好)。

于 2018-10-26T17:46:05.950 回答