如何使用groovy获取Jenkins作业的git scm url

时间:2014-07-14 16:21:39

标签: git groovy jenkins

有没有办法通过groovy在Jenkins作业中获取scm git repo url字符串?

2 个答案:

答案 0 :(得分:6)

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);    
      }
    } 
  }  
}

答案 1 :(得分:1)

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);
        }
    }
}}