java - Jenkins 插件 : Connect jelly and java

标签 java jenkins hudson jenkins-plugins jelly

我目前正在开发我的第一个 Jenkins 插件。
我需要在通过 java 方法填充的工作页面上有一个下拉菜单,但是果冻和 java 文件似乎不能一起正常工作。

jobMain.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">
<h2>FooBar</h2>
    <f:entry field="selection" title="Choose">
        <f:select />
    </f:entry>
</j:jelly>


JavaClass.java

public class JavaClass implements Action {

private AbstractProject ap;

public JavaClass(AbstractProject ap) {
    this.ap = ap;
}

public String getIconFileName() {
    return null;
}

public String getDisplayName() {
    return "";
}

public String getUrlName() {
    return "something";
}

@Extension
public static final class DescriptorImpl extends TransientProjectActionFactory {

    String selection;

    public DescriptorImpl() throws IOException {
    }

    @DataBoundConstructor
    public DescriptorImpl(String selection) {
        this.selection = selection;
    }

    public ListBoxModel doFillSelectionItems() throws IOException {
        ListBoxModel model = new ListBoxModel();
        model.add("test");
        return model;
    }

    @Override
    public Collection<? extends Action> createFor(AbstractProject target) {
        return Arrays.asList(new JavaClass(target));
    }
  }
}


当我运行它时,作业页面上有一个空的下拉菜单。我可能做错了什么?

最佳答案

不是传递字符串,而是添加一个选项对象。

model.add(new Option("Test"));

关于java - Jenkins 插件 : Connect jelly and java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25623360/

相关文章:

Maven:让 "mvn -Pjenkins"与 "mvn clean install pmd:pmd javadoc:aggregate"相同

java - 如何使用哈希码作为其值来设置索引列?

java - 尝试打印字符串池信息时"statistics unavailable at this time"?

java - 安卓OpenGL ES 2.0 : Text aren't showing up

git - 如何使用 jenkins shell 创建新的 git 分支

docker - 使用Docker代理在Jenkins管道中接收 “nonexistent directory”错误

maven - 尝试通过 jenkins 将 Artifact 部署到 nexus 时出现错误 "Return code is: 401, ReasonPhrase: Unauthorized."

java - 如何在不使用 JGit 下载到本地系统的情况下获取所有提交?

linux - 从 Hudson 运行时 Tomcat 脚本不工作

java - Tomcat 无法通过 Hudson 从 Cargo 插件部署,NoClassDefFoundError