通过来自 jenkins 的 Groovy script.Running 从 artifactory 获取最新的内部版本号以用于多个作业
Get the latest Build Number from artifactory for multiple jobs through Groovy script.Running from jenkins
我正在尝试编写一个小的 groovy 脚本,它将提供来自快照工件存储库的最新内部版本号,并且 运行 来自 jenkins.I 的脚本能够获得最新的为单个作业成功构建编号
import groovy.json.*
import hudson.model.*
import jenkins.model.Jenkins
// get current thread / Executor
def applicationLatestBuild = getLatestBuild('application')
def getLatestBuild( jobName ) {
def searchUrl = "http://xyz.nbc.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]
}
Result is :
Result: 168
我正在尝试为多项工作做这件事,但我做不到,有人能告诉我如何在数组中或为多个工作做这件事吗?jobs.Below 是我正在尝试编写的代码
import groovy.json.*
import hudson.model.*
import jenkins.model.Jenkins
def PoidonServicesLatestBuild = getLatestBuild('PoidonServices')
def applicationLatestBuild = getLatestBuild(application)
def getLatestBuild( jobName ) {
def searchUrl = "http://xyz.nbc.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("PoidonServicesLatestBuild", "${PoidonServicesLatestBuild}"),
new StringParameterValue("applicationLatestBuild ", "${ applicationLatestBuild }"),
])
// add variable to current job
thr.executable.addAction(pa)
下面的代码工作正常,并为我提供了来自快照存储库的最新内部版本号,用于受尊重的作业。
import groovy.json.*
import hudson.model.*
import jenkins.model.Jenkins
def applicationdataLatestBuild = getLatestBuild('PoidonServices')
def CareDiscoveryProductsLatestBuild = getLatestBuild('application')
def thr= Thread.currentThread().executable
def getLatestBuild( jobName ) {
def searchUrl = "http://xyz.nbc.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()
println "Using ${jobName} build ${builds[0]}"
builds[0]
}
def pa = new ParametersAction([
new StringParameterValue("PoidonServicesLatestBuild", "${PoidonServicesLatestBuild}"),
new StringParameterValue("applicationLatestBuild", "${applicationLatestBuild}"),
])
// add variable to current job
thr.addAction(pa)
我正在尝试编写一个小的 groovy 脚本,它将提供来自快照工件存储库的最新内部版本号,并且 运行 来自 jenkins.I 的脚本能够获得最新的为单个作业成功构建编号
import groovy.json.*
import hudson.model.*
import jenkins.model.Jenkins
// get current thread / Executor
def applicationLatestBuild = getLatestBuild('application')
def getLatestBuild( jobName ) {
def searchUrl = "http://xyz.nbc.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]
}
Result is :
Result: 168
我正在尝试为多项工作做这件事,但我做不到,有人能告诉我如何在数组中或为多个工作做这件事吗?jobs.Below 是我正在尝试编写的代码
import groovy.json.*
import hudson.model.*
import jenkins.model.Jenkins
def PoidonServicesLatestBuild = getLatestBuild('PoidonServices')
def applicationLatestBuild = getLatestBuild(application)
def getLatestBuild( jobName ) {
def searchUrl = "http://xyz.nbc.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("PoidonServicesLatestBuild", "${PoidonServicesLatestBuild}"),
new StringParameterValue("applicationLatestBuild ", "${ applicationLatestBuild }"),
])
// add variable to current job
thr.executable.addAction(pa)
下面的代码工作正常,并为我提供了来自快照存储库的最新内部版本号,用于受尊重的作业。
import groovy.json.*
import hudson.model.*
import jenkins.model.Jenkins
def applicationdataLatestBuild = getLatestBuild('PoidonServices')
def CareDiscoveryProductsLatestBuild = getLatestBuild('application')
def thr= Thread.currentThread().executable
def getLatestBuild( jobName ) {
def searchUrl = "http://xyz.nbc.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()
println "Using ${jobName} build ${builds[0]}"
builds[0]
}
def pa = new ParametersAction([
new StringParameterValue("PoidonServicesLatestBuild", "${PoidonServicesLatestBuild}"),
new StringParameterValue("applicationLatestBuild", "${applicationLatestBuild}"),
])
// add variable to current job
thr.addAction(pa)