0
我能夠使用下面的groovy代碼找到最新的內部版本號,但現在我的需求發生了一些變化。目前,我正在嘗試在libs-snaphot-local artifactory存儲庫中找到最新的內部版本號,但現在我想在三個存儲庫中搜索同一作業名稱的最新內部版本號,而不僅僅是libs-snapshot-local搜索作業中所有已定義的artifactory存儲庫中的最新內部版本號
三個額外的存儲庫是libs-alpha-local,libs-stage-local和libs-release-local。因此,代碼應該像它將搜索全部四個工件庫中的最新編譯號以用於例如
libs-snapshot-local is having build number 3,2
libs-alpha-local is having build number 8,4
libs-stage-local is having build number 5,6
libs-release-local is having build number 9,1
so the latest build number would be 9
下面是我的代碼,只在一個倉庫
import groovy.json.*
import hudson.model.*
import jenkins.model.Jenkins
def applicationLatestBuild = getLatestBuild('application')
def DiscoveryProductsLatestBuild = getLatestBuild('DiscoveryProduct')
//String[] testArray = ["libs-snapshot-local", "libs-alpha-local", "libs-stage-local", "libs-release-local"]
def thr= Thread.currentThread().executable
def getLatestBuild(jobName) {
def searchUrl = "http://xyz.test.com:9090/api/search/artifact?name=${jobName}&repos=libs-snapshot-local"
def conn = searchUrl.toURL().openConnection()
conn.setRequestProperty("X-Result-Detail", "info, properties")
def searchResultTxt = conn.content.text
//println "Found: ${searchResultTxt}"
def searchResults = new JsonSlurper().parseText(searchResultTxt)
def builds = searchResults.results.findAll{it.properties["build.number"] != null}.collect { Integer.parseInt(it.properties["build.number"][0]) }.sort().unique().reverse()
builds[0]
}
def pa = new ParametersAction([
new StringParameterValue("applicationLatestBuild", "${applicationLatestBuild}"),
new StringParameterValue("DiscoveryProductsLatestBuild", "${DiscoveryProductsLatestBuild}"),
])
// add variable to current job
thr.addAction(pa)
println (applicationLatestBuild)
println(DiscoveryProductsLatestBuild)