我正在尝试编写一个插件,在全局配置(文本区域)中保留一些文本,然后将其显示在相应作业配置构建步骤下的 HTML block 中...
下面是果冻文件。我基本上希望sampleTextAreaInGlobalConfig 文本区域下的文本进入sampleFieldInJobConfig block ...有没有办法使用SampleBuilder.java 的getter 或构造函数来执行此操作?
global.jelly
<f:entry title="HTML Note" field="sampleFieldInGlobalConfig"
description="Place the HTML here that you'd like to see appear in the 'Note from Jenkins Admin' build step">
<f:textarea name="sampleTextAreaInGlobalConfig"/></f:entry>
config.jelly
<f:entry title="Admin Note" field="sampleFieldInJobConfig"><f:block>
</f:block></f:entry>
SampleBuilder.java 扩展了 Builder
private final String sampleFieldInJobConfig;
// Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
@DataBoundConstructor
public SampleBuilder(String sampleFieldInJobConfig) {
this.sampleFieldInJobConfig= sampleFieldInJobConfig;
}
/**
* We'll use this from the <tt>config.jelly</tt>.
*/
public String getSampleFieldInJobConfig() {
return sampleFieldInJobConfig;
}
更新:
我尝试在 config.jelly 中执行 ${sampleFieldInGlobalConfig} 和 $(it.sampleFieldInGlobalConfig)...但不起作用...
最佳答案
找到了答案并且成功了。
由于此字段是 BuildStepDescriptor 类的一部分,因此您可以通过 ${descriptor.getSampleFieldInGlobalConfig()} 从 jelly 脚本访问它
关于java - Jenkins - 如何将字符串从全局配置传递到作业配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27003036/