public class MyBuilder extends Builder implements SimpleBuildStep {
public void perform(Run<?,?> run, FilePath workspace, Launcher launcher, TaskListener listener) {
String password = ((MyBuilder.DescriptorImpl)getDescriptor()).getPassword().getPlainText(); (1)
// Perform work with the password here, like sending HTTP requests etc.
// Secret#toString will also obtain the plain text, but it's deprecated and will log a warning.
}
@Extension
public static class DescriptorImpl extends BuildStepDescriptor<Builder> {
private Secret password; (2)
public void setPassword(Secret password) {
this.password = password;
}
public Secret getPassword() { (3)
return password;
}
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
req.bindJSON(this, json);
return true;
}
// more code
}
// more code
}