bash Jenkins Email-ext 预发送脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11967191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jenkins Email-ext Pre-send Script
提问by akozin
I want to edit email body in pre-send script in Email-ext Jenkins plugin. What language should I use to write code? Bash script or other? Can you add some piece of code? Thanks.
我想在 Email-ext Jenkins 插件的预发送脚本中编辑电子邮件正文。我应该使用什么语言来编写代码?Bash 脚本还是其他?你能添加一些代码吗?谢谢。
采纳答案by Lionel Alberti
The language you must use is Groovy, you can test your piece of code in the script console under Jenkins > Manage > script for anything that doesn't rely on build specific values.
您必须使用的语言是 Groovy,您可以在 Jenkins > 管理 > 脚本下的脚本控制台中测试您的代码段,以了解不依赖于构建特定值的任何内容。
Example that cancels sending the email if there have been no changes (tested when using Git):
如果没有更改则取消发送电子邮件的示例(在使用 Git 时测试):
if (build.changeSet.emptySet) cancel=true;
Groovy is some sort of convenient scripting language that really uses Java behind the scenes, so you'll probably have to dig into the Jenkins java classes to see what is defined/what objects you can use. For instance the build variable in my sample code is really the java object FreeStyleBuild when I run it on my Jenkins job (which is a free style build job obviously).
Groovy 是一种在幕后真正使用 Java 的便捷脚本语言,因此您可能需要深入研究 Jenkins Java 类以了解定义的内容/可以使用的对象。例如,当我在我的 Jenkins 工作(这显然是一个自由风格的构建工作)上运行它时,我的示例代码中的构建变量实际上是 Java 对象 FreeStyleBuild。

