Skip to content

Instantly share code, notes, and snippets.

@jeykey
Last active July 28, 2020 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeykey/e6eec8974c111b43bd39d79b31074db1 to your computer and use it in GitHub Desktop.
Save jeykey/e6eec8974c111b43bd39d79b31074db1 to your computer and use it in GitHub Desktop.
Setup publish over ftp plugin configuration with groovy.
import hudson.util.Secret;
import jenkins.plugins.publish_over_ftp.BapFtpHostConfiguration;
import jenkins.plugins.publish_over_ftp.options.FtpPluginDefaults;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import jenkins.model.*;
// Plugin configuration
def connectionName = "ftp";
def hostname = "mydomain.com";
def username = "user";
def encryptedPassword = new Secret("password").getEncryptedValue();
def remoteRootDir = "/";
def port = 21;
def timeout = 300000;
def useActiveData = false;
def encoding = "UTF-8";
def disableMakeNestedDirs = false;
def disableRemoteVerification = false;
def plugin = Jenkins.getInstance().getDescriptor("jenkins.plugins.publish_over_ftp.BapFtpPublisherPlugin");
StaplerRequest req = [
bindJSONToList: { a, b ->
return new Collections.SingletonList(new BapFtpHostConfiguration(connectionName, hostname, username, encryptedPassword,
remoteRootDir, port, timeout, useActiveData, encoding, disableMakeNestedDirs, disableRemoteVerification));
},
bindJSON : { a, b ->
return new FtpPluginDefaults();
}
] as StaplerRequest;
plugin.configure(req, new JSONObject());
plugin.save();
println "FTP Publisher successfully configured.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment