Jenkins - 如何将字符串从全局配置传递到作业配置

时间:2014-11-18 20:05:45

标签: java jenkins jenkins-plugins

我正在尝试编写一个插件,我在全局配置中保留一些文本(在文本区域中),然后在相应的作业配置构建步骤下显示在HTML块中...

以下是果冻文件。我基本上希望sampleTextAreaInGlobalConfig文本区域下的文本进入sampleFieldInJobConfig块...有没有办法使用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 扩展了构建器

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)...没有用...

1 个答案:

答案 0 :(得分:1)

找到答案并且有效。

由于此字段是BuildStepDescriptor类的一部分,您可以通过$ {descriptor.getSampleFieldInGlobalConfig()}

从果冻脚本访问它
相关问题