Groovy 给詹金斯找份上游工作
我希望获得所有上游作业,就像控制台输出中一样:Groovy 给詹金斯找份上游工作,groovy,jenkins,Groovy,Jenkins,我希望获得所有上游作业,就像控制台输出中一样: Started by upstream project "allocate" build number 31 originally caused by: Started by upstream project "start" build number 12 originally caused by: 我尝试了以下groovy后期构建: def build = Thread.currentThread().executable def caus
Started by upstream project "allocate" build number 31
originally caused by:
Started by upstream project "start" build number 12
originally caused by:
我尝试了以下groovy后期构建:
def build = Thread.currentThread().executable
def causes= manager.build.getCauses()
for (cause in causes)
{
manager.listener.logger.println "upstream build: " + cause.getShortDescription()
}
但我只得到“分配”,而不是“开始”工作
我也试过了
def build = Thread.currentThread().executable
def test = build.getUpstreamBuilds()
for (up in test)
{
manager.listener.logger.println "test build project: " + up
}
但这是空的
有什么想法吗?您的第一个解决方案就快找到了 实际上,您需要做的是根据它的类型迭代这个
原因的祖先
下面是一段可以帮助您开始的代码示例:
def printCausesRecursively(cause) {
if (cause.class.toString().contains("UpstreamCause")) {
println "This job was caused by " + cause.toString()
for (upCause in cause.upstreamCauses) {
printCausesRecursively(upCause)
}
} else {
println "Root cause : " + cause.toString()
}
}
for (cause in manager.build.causes)
{
printCausesRecursively(cause)
}
您可能需要参考文档来处理所有原因
类型:
希望有帮助
最好的您是否有机会将其改编为系统Groovy脚本?我试图在运行当前生成之前从上游作业获取属性,因此不能使用后期生成groovy,也不能使用manager属性(groovy.lang.MissingPropertyException:无此类属性:类的管理器:Script1)我自己获取:def build=Thread.currentThread().可执行def causs=build.getAction(CauseAction.class).getCauses()因为(原因中的原因){。。。