在Groovy中为Jenkins预发送脚本 [英] Pre send script in groovy for jenkins

查看:150
本文介绍了在Groovy中为Jenkins预发送脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个从属工作.我需要詹金斯(Jenkins)的groovy脚本的帮助,以便为email-ext插件编写预发送脚本.

i have two dependent jobs. i need help for groovy script in jenkins, for writing pre send script for email-ext plugin.

我要检查buid原因是否是上游原因,然后设置cancel variable=true

i want to check whether buid reason is upstream cause, then set cancel variable=true

但是我不知道如何在groovy中为jenkins写条件..对于单独的工作,jenkins中是否有任何单独的类(所以我可以创建实例并调用上游原因)

But i don't know how to write if condition in groovy for jenkins..For seperate jobs, will there be any seperate classes in jenkins(so i can create instance and call upstream cause)

有什么方法可以检查下游作业的生成原因是由于上游造成的.

is there any way to check build cause of downstream job is due to upstream..

请在此代码段上为我提供帮助.

Please help me on this code snippet..

推荐答案

使用 Build.getCauses()方法.它将返回生成原因的列表.遍历它,并检查是否存在 hudson.model.Cause的对象.上游原因.

Use Build.getCauses() method. It will return a list of causes for the build. Loop over it and check if there is an object of hudson.model.Cause.UpstreamCause among them.

要获取构建对象,请使用以下代码片段:

To get the build object, use the following code snippet:

def thr = Thread.currentThread()
def build = thr?.executable

仅供参考,这是完整的 Jenkins模块API的链接.

FYI, here is a link to the complete Jenkins Module API.

这篇关于在Groovy中为Jenkins预发送脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆