Guest User

Untitled

a guest
Aug 22nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. @Extension
  2. public class CustomGlobalConfiguration extends GlobalConfiguration {
  3. /** @return the singleton instance */
  4. public static CustomGlobalConfiguration get() {
  5. return GlobalConfiguration.all().get(CustomGlobalConfiguration.class);
  6. }
  7. private String pcip;
  8. private String userName;
  9. private String password;
  10. public CustomGlobalConfiguration() {
  11. // When Jenkins is restarted, load any saved configuration from disk.
  12. load();
  13. }
  14. public String getPcip() {
  15. return pcip;
  16. }
  17. public String getUserName() {
  18. return userName;
  19. }
  20. public String getPassword() {
  21. return password;
  22. }
  23. @DataBoundSetter
  24. public void setPcip(String pcip) {
  25. this.pcip = pcip;
  26. save();
  27. }
  28. @DataBoundSetter
  29. public void setUserName(String userName) {
  30. this.userName = userName;
  31. save();
  32. }
  33. @DataBoundSetter
  34. public void setPassword(String password) {
  35. this.password = password;
  36. save();
  37. }
  38.  
  39. public class IntegrationLeader extends Builder{
  40. private final String blueprintName, appName;
  41. private static final String USER_AGENT = "Mozilla/5.0";
  42. private static final String POST_PARAMS = "{"length":250}";
  43.  
  44. @DataBoundConstructor
  45. public IntegrationLeader(String blueprintName, String appName) {
  46. this.blueprintName = blueprintName;
  47. this.appName = appName;
  48. }
  49. // We'll use this from the <tt>config.jelly</tt>.
  50. public String getBlueprintName(){
  51. return blueprintName;
  52. }
  53. public String getAppName() {
  54. return appName;
  55. }
  56. @Override
  57. public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
  58. EnvVars envVars = new EnvVars();
  59. final EnvVars env = build.getEnvironment(listener);
  60. PrintStream log = listener.getLogger();
  61. //Expanding appname to include the env variables in it's name
  62. String expandedapp = env.expand(appName);
  63. String ip = getDescriptor().getCalmIP()
  64. //rest of the other stuff
  65. }
  66. @Override
  67. public DescriptorImpl getDescriptor() {
  68. return (DescriptorImpl) super.getDescriptor();
  69. }
  70. @Extension
  71. public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
  72. private String calmIP;
  73. private String calmUser;
  74. private String calmPwd;
  75. public List<String> offers;
  76. public List<String> profiles;
  77. public List<String> projects;
  78. public List<String> actions;
  79. public DescriptorImpl() {
  80. load();
  81. }
  82. public boolean isApplicable(Class<? extends AbstractProject> aClass) {
  83. // Indicates that this builder can be used with all kinds of project types
  84. return true;
  85. }
  86. /**
  87. * This human readable name is used in the configuration screen.
  88. */
  89. public String getDisplayName() {
  90. return "Nutanix Calm Blueprint Launch";
  91. }
  92. @Override
  93. public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
  94. CalmGlobalConfiguration calmGlobalConfiguration = CalmGlobalConfiguration.get();
  95. calmIP = calmGlobalConfiguration.getPcip();
  96. calmUser = calmGlobalConfiguration.getUserName();
  97. calmPwd = calmGlobalConfiguration.getPassword();
  98.  
  99. save();
  100. return super.configure(req, formData);
  101. }
  102. }
  103.  
  104. public class RunActionOnApp extends Builder{
  105. private final String blueprintName, appName;
  106. private static final String USER_AGENT = "Mozilla/5.0";
  107. private static final String POST_PARAMS = "{"length":250}";
  108. // Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
  109. @DataBoundConstructor
  110. public IntegrationLeader(String blueprintName, String appName) {
  111. this.blueprintName = blueprintName;
  112. this.appName = appName;
  113. }
  114. // We'll use this from the <tt>config.jelly</tt>.
  115. public String getBlueprintName(){
  116. return blueprintName;
  117. }
  118. public String getAppName() {
  119. return appName;
  120. }
  121. @Override
  122. public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
  123. EnvVars envVars = new EnvVars();
  124. final EnvVars env = build.getEnvironment(listener);
  125. PrintStream log = listener.getLogger();
  126. //Expanding appname to include the env variables in it's name
  127. String expandedapp = env.expand(appName);
  128. String ip = getDescriptor().getCalmIP()
  129. //rest of the other stuff
  130. }
  131. @Override
  132. public DescriptorImpl getDescriptor() {
  133. return (DescriptorImpl) super.getDescriptor();
  134. }
  135. @Extension // This indicates to Jenkins that this is an implementation of an extension point.
  136. public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
  137. /**
  138. * To persist global configuration information, simply store it in a
  139. * field and call save().
  140. *
  141. * <p>
  142. * If you don't want fields to be persisted, use <tt>transient</tt>.
  143. */
  144. private String calmIP;
  145. private String calmUser;
  146. private String calmPwd;
  147. public List<String> offers;
  148. public List<String> profiles;
  149. public List<String> projects;
  150. public List<String> actions;
  151. private int lastEditorId = 0;
  152. private int lastprofId = 0;
  153. public DescriptorImpl() {
  154. load();
  155. }
  156. public boolean isApplicable(Class<? extends AbstractProject> aClass) {
  157. // Indicates that this builder can be used with all kinds of project types
  158. return true;
  159. }
  160. /**
  161. * This human readable name is used in the configuration screen.
  162. */
  163. public String getDisplayName() {
  164. return "Nutanix Calm Blueprint Launch";
  165. }
  166. @Override
  167. public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
  168. // To persist global configuration information,
  169. // set that to properties and call save().
  170. CalmGlobalConfiguration calmGlobalConfiguration = CalmGlobalConfiguration.get();
  171. calmIP = calmGlobalConfiguration.getPcip();
  172. calmUser = calmGlobalConfiguration.getUserName();
  173. calmPwd = calmGlobalConfiguration.getPassword();
  174. // ^Can also use req.bindJSON(this, formData);
  175. // (easier when there are many fields; need set* methods for this, like setUseFrench)
  176. save();
  177. return super.configure(req, formData);
  178. }
  179. }
Add Comment
Please, Sign In to add comment