Unable to save options in custom SCM plugin

15 views
Skip to first unread message

Berend D.

unread,
Mar 26, 2024, 8:35:33 PM3/26/24
to Jenkins Developers
Hi,

I'm attempting to implement a custom SCM, where I am using the git and subversion plugins as examples on how to do this.

I'm currently stuck on setting the global options for my plugin. I made a jelly template to set the 'sometoolPath' option. My understanding of the @DataBoundConstructor and @DataBoundSetter was that this would cause these to be called when the SCM implementation was configured:

public class MySCM extends SCM implements Serializable {
    // Global configuration options - set from the GUI
    private String sometoolPath;

    @DataBoundConstructor
    public MySCM() {
        System.out.println("Instantiated new instance of MySCM!!!");
    }

    @DataBoundSetter
    public void setSometoolPath(String sometoolPath) {
        System.out.println("Updated path: " + sometoolPath);
        this.sometoolPath = sometoolPath;
    }

    public String getSometoolPath() {
        return sometoolPath;
    }

    ...

    @Override
    public DescriptorImpl getDescriptor() {
        return (DescriptorImpl) super.getDescriptor();
    }

    @Extension
    public static final class DescriptorImpl extends SCMDescriptor<MySCM> {
        public DescriptorImpl() {
            super(MySCM.class, null);
            load();
        }

        @Override
        public SCM newInstance(StaplerRequest req, JSONObject formData) throws FormException {
            MySCM scm = (MySCM) super.newInstance(req, formData);
            return scm;
        }

        @Override
        public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
            save();
            return true;
        }

        @Override
        public String getDisplayName() {
            return "My Cool SCM";
        }
    }
}

But no matter what I do, the setter function is not called.

For completeness, here is the content of MySCM/global.jelly:
<?xml version="1.0" encoding="UTF-8"?>
<?jelly escape-by-default='true'?>
<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:section title="${%Custom SCM Plugin}">
        <f:entry field="sometoolPath" title="${%Path to command}">
            <f:textbox default="customcommand"/>
        </f:entry>
    </f:section>
</j:jelly>

Thanks for any pointers anyone can give me.

Kind regards,
Berend Dekens
Reply all
Reply to author
Forward
0 new messages