我有一个 Jenkins Pipeline 脚本,在其中创建了一个自定义类来表示 AWS AMI。此类扩展了 java.lang.Object 并重写了 java.lang.Object.toString()。明显的意图是我可以在创建字符串时直接引用该对象并获得表示该对象的有用字符串。
不幸的是,jenkins-pipeline 并不这么认为。它很高兴直接尊重对 toString() 方法的请求,但如果没有 toString,我的 println/echo 步骤将被悄悄删除或产生不一致的输出。
请参阅下面的代码片段,了解我正在谈论的内容,以及不同的类(例如 Map)如何精确地按预期工作。
此外,该代码在 Jenkins 脚本控制台中完美运行。但是在詹金斯管道工作中,即使禁用了沙盒;它不是。
public class Ami implements Serializable {
private String nodetype
private String id
private String created
private boolean related
private boolean rebuild
Ami(
String nodetype,
String id = 'None',
String created = 'None',
boolean related = false,
boolean rebuild = false
) {
this.nodetype = nodetype
this.id = id
this.created = created
this.related = related
this.rebuild = rebuild …Run Code Online (Sandbox Code Playgroud)