2015-12-02 61 views
1

排序在詹金斯,我需要有Git Parameter功能,但与标签的创建时间排序选项(不支持那里)。詹金斯git的标签作为参数按日期

我已经实现了我将张贴作为一个答案,帮助他人寻求这种功能的解决方案,但我想听听就可以了意见和建议。

随意提出更多的想法。

回答

2

目前,为了解决这个问题,我用Dynamic Parameter Plug-in和一些我编写为Scriptler的常见问题。

的想法是缓存库的本地副本,在一个临时位置(以后可以重复使用),并与一些git log命令查询。

我的代码是Windows服务器,但可以很容易地改变支持Linux。

def cloneDirName = "c:\\temp\\${repoName}" 

def gitClone = "git clone --bare ${gitURL} ${cloneDirName}" 
def gitPull = "cmd.exe /c cd ${cloneDirName} & git fetch origin +refs/heads/*:refs/heads/* --prune" 
def gitLogTags = "cmd.exe /c cd ${cloneDirName} & git log --date-order --tags --simplify-by-decoration --pretty=format:%D" 

def folder = new File(cloneDirName) 

def proc 
def action 
def text 
def list = [] 


if(!folder.exists()) { 
    folder.mkdirs() 
    proc = gitClone.execute() 
    action = "cloning" 
} else { 
    // Just update the repo 
    proc = gitPull.execute() 
    action = "pulling" 
} 

//println "${action}..." 

proc.waitFor() 

if (proc.exitValue() != 0) { 
    text = "ERROR {$action}" 
} 

action = "getting tags" 
proc = gitLogTags.execute() 
proc.waitFor() 

text = proc.in.text 

// For debug - uncomment and run 
//println "${text}" 
//println "\n\n***\n\n" 

if (proc.exitValue() != 0) { 
    text = "ERROR {$action}" 
    list.add(text) 
} else { 
    text = text.replace("\n", ",") 
    def m = text =~ /tag: [^,]+/ 
    m.each { 
     // For debug - uncomment and run 
     // println it 
     list.add(it.replace("tag:", "")) 
    } 
} 

// For debug - uncomment and run 
//println "\n\n***\n\n" 
list.each { println it } 

此设置工作得很好,但我想知道是否有其他建议。
我主要关心的是需要预取存储库(可能需要一段时间才能存储大型存储库)。

我希望这会有所帮助。