How to Get Information About a Jenkins Job

From WikiHTP

Open your Jenkins instance script console http://yourJenkins:port/script following is an example for how to get information about a sepcific job. copy the code to the console, change the jobName to the required job and click "Run".

/*This script shows how to get basic information about a job and its builds*/
def jenkins = Jenkins.getInstance()
def jobName = "myJob"
def job = jenkins.getItem(jobName)

println "Job type: ${job.getClass()}"
println "Is building: ${job.isBuilding()}"
println "Is in queue: ${job.isInQueue()}"
println "Last successfull build: ${job.getLastSuccessfulBuild()}"
println "Last failed build: ${job.getLastFailedBuild()}"
println "Last build: ${job.getLastBuild()}"
println "All builds: ${job.getBuilds().collect{ it.getNumber()}}"

first we get the Jenkins instance object, then using this instance we get the job object (item). from the job object we can get different information such as: is it currently building, is it in the queue, the last build, last build by status, and a lot more.

About This Tutorial

This page was last edited on 31 January 2019, at 00:06.