首页 > 解决方案 > 如何在我正在开发的插件中添加凭据的下拉字段

问题描述

我对扩展 Jenkins 有点陌生,我想知道如何生成代码来添加凭据下拉菜单,就像这张图片中的那样。 我看过一些例子并注意到他们使用了这个果冻代码

<f:entry title="${%Credentials}" field="credentialsId">
  <c:select/>
</f:entry>

但是当我在构建作业设置中实现这个我的凭据行时不包含下拉菜单。

标签: javajenkins-pluginscredentialsjelly

解决方案


笔记想通了。为他人利益发布答案。为了动态填充列表,您必须像下面的方法一样创建一个 doFillCredentialsIdItems,并将导入添加到凭证插件。

public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item, @QueryParameter String credentialsId) {
        StandardListBoxModel result = new StandardListBoxModel();
                        return result
                .includeEmptyValue()
                .includeAs(ACL.SYSTEM, Jenkins.get(),
                 UsernamePasswordCredentialsImpl.class)
                .includeCurrentValue(credentialsId);
        }

推荐阅读