Jenkins插件如何获取工作信息 [英] Jenkins Plugin How to get Job information
本文介绍了Jenkins插件如何获取工作信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作一个Jenkins插件.您如何从插件获取工作信息?我知道
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.
推荐答案
我编写了以下groovy脚本,以从作业中获取所有内部版本号.
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)
Job jenkins API可以为您提供其他获取信息的句柄关于乔布斯
The Job jenkins API can give you additional handles to get information about Jobs
这篇关于Jenkins插件如何获取工作信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文