2015-12-02 58 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 } 

此設置工作得很好,但我想知道是否有其他建議。
我主要關心的是需要預取存儲庫(可能需要一段時間才能存儲大型存儲庫)。

我希望這會有所幫助。