Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get git scm url for a Jenkins job with groovy

Is there a way to get the scm git repo url string inside a Jenkins job with groovy?

like image 427
wapgui Avatar asked Feb 12 '23 12:02

wapgui


2 Answers

import jenkins.model.*;
import hudson.model.*;
import hudson.tasks.*;
import hudson.plugins.git.*;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;

for(project in Hudson.instance.items) {
  scm = project.scm;
  if (scm instanceof hudson.plugins.git.GitSCM) {
    for (RemoteConfig cfg : scm.getRepositories()) {
      for (URIish uri : cfg.getURIs()) {
        println("SCM " + uri.toString() + " for project " + project);    
      }
    } 
  }  
}
like image 165
wapgui Avatar answered Feb 15 '23 02:02

wapgui


Jenkins.instance.getAllItems(Job.class).each{
scm = it.scm;
project = it;
if (scm instanceof hudson.plugins.git.GitSCM) {
    scm.getRepositories().each{
        it.getURIs().each{
            println("SCM " + it.toString() + " in " + project);
        }
    }
}}
like image 24
chino.garcia Avatar answered Feb 15 '23 00:02

chino.garcia