Allow running a smooth step more than once

I am creating a plugin for Jenkins that adds a new type post post step (Publisher). When I try to create a new task, I can only add my new step once (it may not be available in the menu after assembly). I would like to be able to add it as many times as I like to the same work with a different configuration for each of them (i.e., Different instances of my Publisher subclass). How can this be done, and what does Jenkins say only allow him to be added once?

Update

It seems like this has something to do with the <f:repeatable>jelly element , but I cannot figure out how to use it, and I cannot find any information about it. I tried to monitor the HTML Publisher plugin, but kept getting errors. If anyone can explain how to use this, or point to a link, that would be great!

+4
source share
1 answer

Finally, you can understand this after much trial and error based on the HTML Publisher plugin.

, , , , , "". : name, file height. 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:entry>
        <f:repeatable field='targets'>
            <f:textbox field='name' default='Report' />
            <f:textbox field='file' default='report.html' />
            <f:number field='height' default='300' /> px
            <f:repeatableDeleteButton value='Delete report' />
        </f:repeatable>
    </f:entry>
</j:jelly>

- - :

Build step config

, "" .

, "" - . , , , , , , AbstractDescribablyImpl. :

public static class Target extends AbstractDescribableImpl<Target>
{
    public String name;
    public String file;
    public int height;

    // Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
    @DataBoundConstructor
    public Target(String name, String file, int height) {
        this.name = name;
        this.file = file;
        this.height = height;
        if(this.name == null) {
            throw new RuntimeException("Name is NULL!");
        }
    }

    public String getName() {
        return this.name;
    }

    public String getFile() {
        return this.file;
    }

    public int getHeight() {
        return this.height;
    }

    @Extension
    public static class DescriptorImpl extends Descriptor<Target> {
        @Override
        public String getDisplayName() {
            return "";
        }
    }
}

, .

, BuildStep, , , "" ( Target , ). , :

public class EmbedReportPublisher extends Publisher
{
    private List<Target> targets;

    public static class Target extends AbstractDescribableImpl<Target>
    {
        // ... shown above ...
    }

    @DataBoundConstructor
    public EmbedReportPublisher(List<Target> targets) {
        if (targets == null) {
            this.targets = new ArrayList<Target>(0);
        }
        else {
            this.targets = new ArrayList<Target>(targets);
        }
    }
}

. perform , getProjectActions, , , this.targets - , .

+1

Source: https://habr.com/ru/post/1545400/


All Articles