我有一个包含脚本的工作流程作业列表:println("hello");
我可以使用以下代码以字符串形式返回脚本的值:
for (job in hudson.model.Hudson.instance.getView(nomeView).items) {
if (job.name.contains("myJobs")) {
script = job.getDefinition().getScript();
println(script);
}
}
结果:
println("hello");
println("hello");
println("hello");
println("hello");
println("hello");
println("hello");
println("hello");
... number of jobs
但是我不仅要获取脚本,还要对其进行修改。
script = job.getDefinition().getScript();
job.getDefinition().setScript(script + "println("world");"; //there are something like this?
println(script);
我希望结果是这样的:
println("hello");
println("world");
println("hello");
println("world");
println("hello");
println("world");
println("hello");
println("world");
... number of jobs
答案 0 :(得分:0)
尝试
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition
for (job in hudson.model.Hudson.instance.getView(nomeView).items) {
if (job.name.contains("myJobs")) {
script = job.getDefinition().getScript();
println(script);
job.setDefinition(new CpsFlowDefinition(script + "println("world");", true)
script_new = job.getDefinition().getScript();
println(script_new);
}
}