2016-09-27 1 views
0

아래의 그루비 코드로 최신 빌드 번호를 찾을 수 있지만 이제는 제 요구 사항이 조금 변경되었습니다. 현재 libs-snaphot-local artifactory 저장소에서만 최신 빌드 번호를 찾으려고하지만 libs-snapshot-local 대신 동일한 작업 이름에 대해 세 개의 저장소에서 최신 빌드 번호를 검색하려고합니다.작업에 대한 모든 정의 된 인공 지능 저장소의 최신 빌드 번호 검색

세 개의 추가 리포지토리는 libs-alpha-local, libs-stage-local 및 libs-release-local입니다. 따라서 코드는 예를 들어 4 개의 모든 인공 저장소에있는 최신 빌드 번호를 검색하는 것과 같아야합니다. 다음은

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) 

답변

0

당신은이 라인 여기에 다른 저장소를 추가 할 필요가 대답을한다 검색되는 내 코드이며, 그것은 당신의 원하는 줄 것이다 결과.

데프 searchUrl = "http://xyz.test.com:9090/api/search/artifact?name= $ {작업 이름} &의 repos = libs와 스냅 샷 로컬, libs와 알파 - 지역, libs와 단계 로컬, libs와 릴리스 로컬"

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,libs-alpha-local,libs-stage-local,libs-release-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)