Jenkins 插件复选框:GUI 值不同于 config.xml

Jenkins plugin checkbox: GUI value differs from config.xml

我正在对 Jenkins 插件 (https://wiki.jenkins-ci.org/display/JENKINS/Stash+pullrequest+builder+plugin) 进行更改,因为我想为其添加几个选项。

但是,在 config.jelly 添加了两个新复选框后,它们似乎无法通过 GUI 在作业配置中正常工作。

config.jelly:

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
  ...
  <f:advanced>
  ...
    <f:entry title="Report build started to Stash?" field="reportBuildStartedToStash">
      <f:checkbox default="true"/>
    </f:entry>
    <f:entry title="Report build result to Stash?" field="reportBuildStatusToStash">
      <f:checkbox default="true"/>
  </f:advanced>
</j:jelly>

如果我像这样将此插件添加到作业中:

然后这两个复选框默认为 "true" 正如预期的那样。这反映在 config.xml:

  <triggers>
    <stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger plugin="stash-pullrequest-builder@1.3.1-SNAPSHOT">
      ...
      <reportBuildStartedToStash>true</reportBuildStartedToStash>
      <reportBuildStatusToStash>true</reportBuildStatusToStash>
    </stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger>
  </triggers>

但是,如果我取消选中这些复选框,保存更改,然后重新加载“作业配置”页面,这些复选框将再次被选中。

这可能是我的 .jelly 配置有问题吗?我不明白如何或为什么。

作为参考,我的分支在这里:https://github.com/blaffoy/stash-pullrequest-builder-plugin/tree/optional-messages-to-stash

这个问题似乎与 here 提出的问题相同,但建议的解决方案并没有解决我的问题。即,将<f:checkbox default="true"/>替换为<f:checkbox/>

这将通过在 StashBuildTrigger.java 中的 getter 方法前面加上 "is" 前缀来工作,例如

public boolean isReportBuildStartedToStash() 
public boolean isDeleteBuildStartedToStash()
public boolean isReportBuildStatusToStash()

我认为这也适用于 "get" 前缀,但我还没有测试过。根据 jenkins plugin doc:

Define getters for the configuration fields, or make the fields "public final". This allows Jelly script to read the values to populate the configuration page.

A few things to notice: the 'get' was automatically stripped from the method name, and the first letter of the remaining method name was lower-cased. I'd recommend using the Java convention for naming methods (e.g. starting getters with 'get' and using CamelCase) so that Jelly can always find the methods.

示例java naming conventions

Use the prefixes get and set for getter and setter methods. ... If the method returns a boolean value, use is or has as the prefix for the method name.