2016-09-27 6 views
0

私は以下のgroovyコードで最新のビルド番号を見つけることができました。現時点では、libs-snapshot-local artifactoryリポジトリだけで最新のビルド番号を検索しようとしていますが、libs-snapshot-localではなく同じジョブ名に対して最新のビルド番号を検索したいのですジョブのために定義されたすべての工芸品リポジトリの最新のビルド番号を検索

3つの余分なリポジトリは、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 

だけ1つのリポジトリ以下

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

で検索された私のコードは、あなたがここでこの行の他のリポジトリを追加する必要があり、それはあなたの希望を与える答え

です結果。

DEF searchUrl = "http://xyz.test.com:9090/api/search/artifact?name= $ {jobNameは} &レポ= 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) 
関連する問題