如何獲取有關 Jenkins 工作的資訊
開啟你的 jenkins 例項指令碼控制檯 http:// yourJenkins:port / script 以下是如何獲取有關特定作業的資訊的示例。將程式碼複製到控制檯,將 jobName 更改為所需的作業,然後單擊執行。
/*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()}}"
首先我們獲取 Jenkins 例項物件,然後使用此例項獲取作業物件(item)。從作業物件中我們可以得到不同的資訊,例如:它當前正在構建,它是在佇列中,最後一個構建,最後一個按狀態構建,還有更多。