我有一些 Groovy 代码,打算在多个 Jenkins Groovy Post Build 插件中重复使用。我应该怎么做呢?是否有地方可以将脚本存储在全局变量中,并在需要的作业中调用它?
evaluate(new File("C:\\test.groovy"))
// Get an Instance of the Build object, and from there
// the channel from the Master to the Workspace
build = Thread.currentThread().executable
channel = build.workspace.channel;
// Open a FilePath to the script
fp = new FilePath(channel, build.workspace.toString() + "<relative path to the script in Unix notation>")
// Some have suggested that the "Not NULL" check is redundant
// I've kept it for completeness
if(fp != null)
{
// 'Evaluate' requires a string, so read the file contents to a String
script = fp.readToString();
// Execute the script
evaluate(script);
}
JENKINS_HOME/scriptler/scripts
目录中使用,这样我们就可以避免手动复制文件到Jenkins主节点。def env = manager.build.getEnvironment(manager.listener) evaluate(new File(env['JENKINS_HOME'] + "\\scriptler\\scripts\\GroovyForPostBuild.groovy"))