jenkins 为什么每次执行作业时都会清除发送前脚本?

sq1bmfud  于 2022-11-21  发布在  Jenkins
关注(0)|答案(1)|浏览(139)

我配置所有jenkins作业的发送前脚本与以下脚本:

for(job in Hudson.instance.items) {
    def list = job.getPublishersList()
    for (publisher in list) {
        if (publisher instanceof hudson.plugins.emailext.ExtendedEmailPublisher) {
            def preSendScript = "your script here"
            publisher.setPresendScript(preSendScript)
        }
    }
}

从脚本控制台执行脚本后,我发现作业的发送前脚本被修改:

但是,当我运行作业时,发送前脚本由于被清除而不起作用。
为什么每次执行作业时都会清除发送前脚本?

x4shl7ld

x4shl7ld1#

未保存配置更改。
我们应该在publisher.setPresendScript(preSendScript)之后使用job.save()
工作脚本应为:

for(job in Hudson.instance.items) {
    def list = job.getPublishersList()
    for (publisher in list) {
        if (publisher instanceof hudson.plugins.emailext.ExtendedEmailPublisher) {
            def preSendScript = "your script here"
            publisher.setPresendScript(preSendScript)
        }
    }
    // must have
    job.save()
}

相关问题