{"id":638,"date":"2019-07-02T08:38:34","date_gmt":"2019-07-02T12:38:34","guid":{"rendered":"https:\/\/crossan007.dev\/blog\/?p=638"},"modified":"2019-07-02T08:38:35","modified_gmt":"2019-07-02T12:38:35","slug":"obtaining-git-repo-url-from-jenkins-changeset-unsolved","status":"publish","type":"post","link":"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/","title":{"rendered":"Obtaining Git Repo URL from Jenkins Changeset: Unsolved"},"content":{"rendered":"\n<div class=\"twitter-share\"><a href=\"https:\/\/twitter.com\/intent\/tweet?via=crossan007\" class=\"twitter-share-button\">Tweet<\/a><\/div>\n\n<p>I&#8217;m attempting to obtain a Git Repo URL from a Jenkins Change set in a Groovy Scripted Pipeline, but I keep running into the same issue: the <code>browser<\/code> property (obtained via <code>.getBrowser()<\/code>) on my <code>hudson.plugins.git.GitChangeSetList<\/code> object is undefined.<\/p>\n\n\n\n<p>I&#8217;m running the below code (with inline &#8220;status comments&#8221;) from the Jenkins groovy script console in an attempt to extract the RepoUrl from Chagesets in a Jenkins Multi branch groovy scripted pipeline:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndef job = Jenkins.instance.getItem(&quot;MyJenkinsJob&quot;) \ndef branch = job.getItems().findAll({ \n            item -&gt; item.getDisplayName().contains(&quot;Project\/CreateChangeLogs&quot;)\n        })\n\nprintAllMethods(branch&#91;0].getFirstBuild()) \/\/this works, and is a org.jenkinsci.plugins.workflow.job.WorkflowRun\n\ndef builds = branch&#91;0].getBuilds()\ndef currentBuild = builds&#91;0]\n\ncurrentBuild.changeSets.collect { \n  printAllMethods(it) \/\/ this works too, and is a hudson.plugins.git.GitChangeSetList.\n  \/\/ enumerated methods are equals(); getClass(); hashCode(); notify(); notifyAll(); toString(); wait(); createEmpty(); getBrowser(); getItems(); getKind(); getRun(); isEmptySet(); getLogs(); iterator(); \n\n  it.getBrowser().repoUrl \/\/ this fails\n  \/\/ the error is java.lang.NullPointerException: Cannot get property 'repoUrl' on null object\n}\n<\/pre><\/div>\n\n\n<p>I found the utility class for PrintAllMethods here (https:\/\/bateru.com\/news\/2011\/11\/code-of-the-day-groovy-print-all-methods-of-an-object\/):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n  void printAllMethods( obj ){\n    if( !obj ){\n        println( &quot;Object is null\\r\\n&quot; );\n        return;\n    }\n    if( !obj.metaClass &amp;&amp; obj.getClass() ){\n        printAllMethods( obj.getClass() );\n        return;\n    }\n    def str = &quot;class ${obj.getClass().name} functions:\\r\\n&quot;;\n    obj.metaClass.methods.name.unique().each{ \n        str += it+&quot;(); &quot;; \n    }\n    println &quot;${str}\\r\\n&quot;;\n}\n<\/pre><\/div>\n\n\n<p>The API spec for <a href=\"https:\/\/javadoc.jenkins.io\/plugin\/git\/hudson\/plugins\/git\/GitChangeSetList.html\">GitChangeSetList<\/a> indicates that in extends <a href=\"https:\/\/javadoc.jenkins.io\/hudson\/scm\/ChangeLogSet.html?is-external=true\">hudson.scm.ChangeLogSet<\/a> which implements <code>getBrowser()<\/code>, so the call <em>should<\/em> be valid.<\/p>\n\n\n\n<p>Additionally, the source for <a href=\"https:\/\/github.com\/jenkinsci\/git-plugin\/blob\/master\/src\/main\/java\/hudson\/plugins\/git\/GitChangeSetList.java\">GitChangeSetList<\/a> invokes the <code>super()<\/code> constructor with the passed <code>browser<\/code> object.<\/p>\n\n\n\n<p>At this point, I&#8217;m probably going to continue diving through the source code until I figure it out. <\/p>\n\n\n\n<p>It looks like this is a documented issue with Jenkins: https:\/\/issues.jenkins-ci.org\/browse\/JENKINS-52747<\/p>\n\n\n\n<p>And a (somewhat) related StackOverflow post: https:\/\/devops.stackexchange.com\/questions\/3798\/determine-the-url-for-a-scm-trigger-from-inside-the-build<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m attempting to obtain a Git Repo URL from a Jenkins Change set in a Groovy Scripted Pipeline, but I keep running into the same issue: the browser property (obtained via .getBrowser()) on my hudson.plugins.git.GitChangeSetList object is undefined. I&#8217;m running the below code (with inline &#8220;status comments&#8221;) from the Jenkins groovy script console in an &hellip; <a href=\"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Obtaining Git Repo URL from Jenkins Changeset: Unsolved<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[259],"tags":[260,157,234,231],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Obtaining Git Repo URL from Jenkins Changeset: Unsolved - Charles&#039; Blog\" \/>\n<meta property=\"og:description\" content=\"I&#8217;m attempting to obtain a Git Repo URL from a Jenkins Change set in a Groovy Scripted Pipeline, but I keep running into the same issue: the browser property (obtained via .getBrowser()) on my hudson.plugins.git.GitChangeSetList object is undefined. I&#8217;m running the below code (with inline &#8220;status comments&#8221;) from the Jenkins groovy script console in an &hellip; Continue reading Obtaining Git Repo URL from Jenkins Changeset: Unsolved &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/\" \/>\n<meta property=\"og:site_name\" content=\"Charles&#039; Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-02T12:38:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-07-02T12:38:35+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"crossan007\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/crossan007.dev\/blog\/#website\",\"url\":\"https:\/\/crossan007.dev\/blog\/\",\"name\":\"Charles&#039; Blog\",\"description\":\"SharePoint | PowerShell | Exchange | SCCM | Ubuntu | PHP | JavaScript | A\/V Live Production | More...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/crossan007.dev\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/#webpage\",\"url\":\"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/\",\"name\":\"Obtaining Git Repo URL from Jenkins Changeset: Unsolved - Charles&#039; Blog\",\"isPartOf\":{\"@id\":\"https:\/\/crossan007.dev\/blog\/#website\"},\"datePublished\":\"2019-07-02T12:38:34+00:00\",\"dateModified\":\"2019-07-02T12:38:35+00:00\",\"author\":{\"@id\":\"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979\"},\"breadcrumb\":{\"@id\":\"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/crossan007.dev\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Obtaining Git Repo URL from Jenkins Changeset: Unsolved\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979\",\"name\":\"crossan007\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/crossan007.dev\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g\",\"caption\":\"crossan007\"},\"url\":\"https:\/\/crossan007.dev\/blog\/author\/crossan007\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/","og_locale":"en_US","og_type":"article","og_title":"Obtaining Git Repo URL from Jenkins Changeset: Unsolved - Charles&#039; Blog","og_description":"I&#8217;m attempting to obtain a Git Repo URL from a Jenkins Change set in a Groovy Scripted Pipeline, but I keep running into the same issue: the browser property (obtained via .getBrowser()) on my hudson.plugins.git.GitChangeSetList object is undefined. I&#8217;m running the below code (with inline &#8220;status comments&#8221;) from the Jenkins groovy script console in an &hellip; Continue reading Obtaining Git Repo URL from Jenkins Changeset: Unsolved &rarr;","og_url":"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/","og_site_name":"Charles&#039; Blog","article_published_time":"2019-07-02T12:38:34+00:00","article_modified_time":"2019-07-02T12:38:35+00:00","twitter_misc":{"Written by":"crossan007","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/crossan007.dev\/blog\/#website","url":"https:\/\/crossan007.dev\/blog\/","name":"Charles&#039; Blog","description":"SharePoint | PowerShell | Exchange | SCCM | Ubuntu | PHP | JavaScript | A\/V Live Production | More...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/crossan007.dev\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/#webpage","url":"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/","name":"Obtaining Git Repo URL from Jenkins Changeset: Unsolved - Charles&#039; Blog","isPartOf":{"@id":"https:\/\/crossan007.dev\/blog\/#website"},"datePublished":"2019-07-02T12:38:34+00:00","dateModified":"2019-07-02T12:38:35+00:00","author":{"@id":"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979"},"breadcrumb":{"@id":"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/crossan007.dev\/blog\/jenkins\/obtaining-git-repo-url-from-jenkins-changeset-unsolved\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/crossan007.dev\/blog\/"},{"@type":"ListItem","position":2,"name":"Obtaining Git Repo URL from Jenkins Changeset: Unsolved"}]},{"@type":"Person","@id":"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979","name":"crossan007","image":{"@type":"ImageObject","@id":"https:\/\/crossan007.dev\/blog\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g","caption":"crossan007"},"url":"https:\/\/crossan007.dev\/blog\/author\/crossan007\/"}]}},"_links":{"self":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts\/638"}],"collection":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/comments?post=638"}],"version-history":[{"count":1,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts\/638\/revisions"}],"predecessor-version":[{"id":639,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts\/638\/revisions\/639"}],"wp:attachment":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/media?parent=638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/categories?post=638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/tags?post=638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}