I'm trying to make a Jenkins plugin. How do you get job information from the plugin? I know
public String getShortName(Job job) { ... }
However I do not know how to call this method.
I wrote the below groovy script to get all the build numbers from a job.
import hudson.model.*
BUILD_JOB_NAME = "${BUILD_JOB_NAME}"
def getJobs() {
def hi = Hudson.instance
return hi.getItems(Job)
}
def getBuildJob() {
def buildJob = null
def jobs = getJobs()
(jobs).each { job ->
if (job.displayName == BUILD_JOB_NAME) {
buildJob = job
}
}
return buildJob
}
def getAllBuildNumbers(Job job) {
def buildNumbers = []
(job.getBuilds()).each { build ->
buildNumbers.add(build.number)
}
return buildNumbers
}
def buildJob = getBuildJob()
return getAllBuildNumbers(buildJob)
The Job jenkins API can give you additional handles to get information about Jobs