Reputation: 16673
I followed Groovy to list all jobs to get a list of my job names, and got the exact "fullName" of my job, which is...
Microservice/build/feature%2Fdev-26387-split-micro-deploy
Now I have this to try to get all the successful build numbers for this job. The return values are just for debugging to see which value I'm returning, and I'm returning a list with the number "43", meaning, the getJobs() function returned a null, meaning it wasn't able to find the job object. Why?
import hudson.model.*
BUILD_JOB_NAME = "Microservice/build/feature%2Fdev-26387-split-micro-deploy"
def getJobs() {
def hi = Hudson.instance
return hi.getItems(Job)
}
def getBuildJob() {
def buildJob = null
def jobs = getJobs()
(jobs).each { job ->
if (job.fullName == BUILD_JOB_NAME) {
// WHY IS THIS NOT WORKING???
buildJob = job
}
}
return buildJob
}
def getAllBuildNumbers(Job job) {
try {
def buildNumbers = []
(job.getBuilds()).each { build ->
def status = build.getBuildStatusSummary().message
if (status.contains("stable") || status.contains("normal")) {
buildNumbers.add(build.number)
}
}
/// return buildNumbers
return ["44"]
}
catch (Throwable t) {
return ["45"]
}
}
def buildJob = getBuildJob()
if (buildJob == null) {
return ['43']
}
return getAllBuildNumbers(buildJob)
Upvotes: 0
Views: 218
Reputation: 3018
Use return hi.getAllItems(Job)
instead and it should work. Also, ensure your BUILD_JOB_NAME is set to correct job name. To check the job name, run Hudson.instance.getAllItems(Job).each { println(it.fullName) }
from Jenkins -> Manage Jenkins -> Script Console
Upvotes: 1