Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the repository name or URL of a GitChangeSet object?

I have a GitChangeSet object (that ultimately came from a build). I would like to find the repository name or URL associated with that commit. However, none of the properties of the object seem to hint at where this commit ultimately came from. E.g.:

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

I got this commit object by iterating over build.changeSets (which I believe comes from the class hudson.model.AbstractBuild). I do know that this particular commit came from a global Shared Library repository, not the main repository associated with this build, but I don't see any obvious way to extract that information programmatically. How can I programmatically determine which repository the GitChangeSet objects (or other objects in hudson.model.AbstractBuild.changeSets in general) came from?


For context, I'm developing an e-mail report for failed builds that, among other things, collects a list of commits associated with the failed build. Since I have complex upstream/downstream relationships between my jobs, a commit in one repository may trigger a series of builds as successful builds trigger downstream jobs that depend on the upstream ones. Additionally, there are other repositories associated with my builds, in particular a global Shared Library repository. I would like my report to mention what commits are ultimately responsible for the series of builds resulting in the current one. Finding these upstream commits has not been too painful so far (thanks to UpstreamJobCause), but I've become hung up on determining where those commits ultimately came from. I would appreciate any suggestions on alternative approaches to this problem in the comments if you don't know of an answer to my question as stated.

like image 466
jayhendren Avatar asked Dec 06 '25 18:12

jayhendren


1 Answers

Use getChangeSetLink to build the URL for you. In this way you don't need to hard-code any part of the URL.

build.changeSets.each { changeSetList ->
  def browser = changeSetList.browser
  changeSetList.items.each { changeSet -> 
    println browser.getChangeSetLink(changeSet)
  }
}
like image 136
Lorenzo Dalla Vecchia Avatar answered Dec 08 '25 06:12

Lorenzo Dalla Vecchia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!