implements IOpenShiftPluginDescriptor {
54 | /**
55 | * To persist global configuration information, simply store it in a
56 | * field and call save().
57 | *
58 | *
59 | * If you don't want fields to be persisted, use transient.
60 | */
61 |
62 | /**
63 | * In order to load the persisted global configuration, you have to call
64 | * load() in the constructor.
65 | */
66 | public DescriptorImpl() {
67 | load();
68 | }
69 |
70 | public FormValidation doCheckJsonyaml(@QueryParameter String value)
71 | throws IOException, ServletException {
72 | return ParamVerify.doCheckJsonyaml(value);
73 | }
74 |
75 | public boolean isApplicable(Class extends AbstractProject> aClass) {
76 | // Indicates that this builder can be used with all kinds of project
77 | // types
78 | return true;
79 | }
80 |
81 | /**
82 | * This human readable name is used in the configuration screen.
83 | */
84 | public String getDisplayName() {
85 | return DISPLAY_NAME;
86 | }
87 |
88 | @Override
89 | public boolean configure(StaplerRequest req, JSONObject formData)
90 | throws FormException {
91 | // To persist global configuration information,
92 | // pull info from formData, set appropriate instance field (which
93 | // should have a getter), and call save().
94 | save();
95 | return super.configure(req, formData);
96 | }
97 |
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/dsl/OpenShiftBaseStep.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline.dsl;
2 |
3 | import java.io.IOException;
4 | import java.io.Serializable;
5 |
6 | import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
7 | import org.kohsuke.stapler.DataBoundSetter;
8 |
9 | import com.openshift.jenkins.plugins.pipeline.Auth;
10 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftPlugin;
11 | //import com.openshift.restclient.authorization.TokenAuthorizationStrategy;
12 |
13 | import jenkins.tasks.SimpleBuildStep;
14 | import hudson.FilePath;
15 | import hudson.Launcher;
16 | import hudson.model.AbstractBuild;
17 | import hudson.model.BuildListener;
18 | import hudson.model.Run;
19 | import hudson.model.TaskListener;
20 |
21 | public abstract class OpenShiftBaseStep extends AbstractStepImpl implements
22 | SimpleBuildStep, Serializable, IOpenShiftPlugin {
23 |
24 | protected String apiURL;
25 | protected String namespace;
26 | protected String authToken;
27 | protected String verbose;
28 | // marked transient so don't serialize these next 2 in the workflow plugin
29 | // flow; constructed on per request basis
30 | // protected transient TokenAuthorizationStrategy bearerToken;
31 | protected transient Auth auth;
32 |
33 | protected OpenShiftBaseStep() {
34 | }
35 |
36 | // generically speaking, Jenkins will always pass in non-null field values.
37 | // However, as we have periodically
38 | // added new fields, jobs created with earlier versions of the plugin get
39 | // null for the new fields. Hence,
40 | // we have introduced the generic convention (even for fields that existed
41 | // in the initial incarnations of the plugin)
42 | // of insuring nulls are not returned for field getters
43 |
44 | public String getApiURL() {
45 | return apiURL;
46 | }
47 |
48 | @DataBoundSetter
49 | public void setApiURL(String apiURL) {
50 | this.apiURL = apiURL != null ? apiURL.trim() : null;
51 | }
52 |
53 | public String getNamespace() {
54 | return namespace;
55 | }
56 |
57 | @DataBoundSetter
58 | public void setNamespace(String namespace) {
59 | this.namespace = namespace != null ? namespace.trim() : null;
60 | }
61 |
62 | public String getAuthToken() {
63 | return authToken;
64 | }
65 |
66 | @DataBoundSetter
67 | public void setAuthToken(String authToken) {
68 | this.authToken = authToken != null ? authToken.trim() : null;
69 | }
70 |
71 | public String getVerbose() {
72 | return verbose;
73 | }
74 |
75 | @DataBoundSetter
76 | public void setVerbose(String verbose) {
77 | this.verbose = verbose != null ? verbose.trim() : null;
78 | }
79 |
80 | @Override
81 | public void setAuth(Auth auth) {
82 | this.auth = auth;
83 | }
84 |
85 | @Override
86 | public Auth getAuth() {
87 | return auth;
88 | }
89 |
90 | /*
91 | * @Override public TokenAuthorizationStrategy getToken() { return
92 | * bearerToken; }
93 | *
94 | * @Override public void setToken(TokenAuthorizationStrategy token) {
95 | * this.bearerToken = token; }
96 | */
97 | @Override
98 | public String getBaseClassName() {
99 | return OpenShiftBaseStep.class.getName();
100 | }
101 |
102 | // this is the workflow plugin path
103 | @Override
104 | public void perform(Run, ?> run, FilePath workspace, Launcher launcher,
105 | TaskListener listener) throws InterruptedException, IOException {
106 | this.doIt(run, workspace, launcher, listener);
107 | }
108 |
109 | // this is the classic jenkins build step path
110 | @Override
111 | public boolean perform(AbstractBuild, ?> build, Launcher launcher,
112 | BuildListener listener) throws IOException, InterruptedException {
113 | return this.doIt(build, launcher, listener);
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/OpenShiftBuilder.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline;
2 |
3 | import com.openshift.jenkins.plugins.pipeline.model.GlobalConfig;
4 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftBuilder;
5 | import com.openshift.jenkins.plugins.pipeline.model.ITimedOpenShiftPlugin;
6 | import hudson.Extension;
7 | import hudson.tasks.Builder;
8 | import hudson.util.FormValidation;
9 | import org.kohsuke.stapler.DataBoundConstructor;
10 | import org.kohsuke.stapler.QueryParameter;
11 |
12 | import javax.servlet.ServletException;
13 | import java.io.IOException;
14 | import java.util.List;
15 |
16 | public class OpenShiftBuilder extends TimedOpenShiftBaseStep implements
17 | IOpenShiftBuilder, ITimedOpenShiftPlugin {
18 |
19 | protected final String bldCfg;
20 | protected final String commitID;
21 | protected final String buildName;
22 | protected final String showBuildLogs;
23 | protected final String checkForTriggeredDeployments;
24 | protected final List envVars;
25 |
26 | // Fields in config.jelly must match the parameter names in the
27 | // "DataBoundConstructor"
28 | @DataBoundConstructor
29 | public OpenShiftBuilder(String apiURL, String bldCfg, String namespace,
30 | List env, String authToken, String verbose,
31 | String commitID, String buildName, String showBuildLogs,
32 | String checkForTriggeredDeployments, String waitTime,
33 | String waitUnit) {
34 | super(apiURL, namespace, authToken, verbose, waitTime, waitUnit);
35 | this.bldCfg = bldCfg != null ? bldCfg.trim() : null;
36 | this.envVars = env;
37 | this.commitID = commitID != null ? commitID.trim() : null;
38 | this.buildName = buildName != null ? buildName.trim() : null;
39 | this.showBuildLogs = showBuildLogs != null ? showBuildLogs.trim()
40 | : null;
41 | this.checkForTriggeredDeployments = checkForTriggeredDeployments != null ? checkForTriggeredDeployments
42 | .trim() : null;
43 | }
44 |
45 | // generically speaking, Jenkins will always pass in non-null field values.
46 | // However, as we have periodically
47 | // added new fields, jobs created with earlier versions of the plugin get
48 | // null for the new fields. Hence,
49 | // we have introduced the generic convention (even for fields that existed
50 | // in the initial incarnations of the plugin)
51 | // of insuring nulls are not returned for field getters
52 |
53 | public String getCommitID() {
54 | return commitID;
55 | }
56 |
57 | public String getBuildName() {
58 | return buildName;
59 | }
60 |
61 | public String getShowBuildLogs() {
62 | return showBuildLogs;
63 | }
64 |
65 | public String getBldCfg() {
66 | return bldCfg;
67 | }
68 |
69 | public List getEnv() {
70 | return envVars;
71 | }
72 |
73 | public String getCheckForTriggeredDeployments() {
74 | return checkForTriggeredDeployments;
75 | }
76 |
77 | /**
78 | * Descriptor for {@link OpenShiftBuilder}. Used as a singleton. The class
79 | * is marked as public so that it can be accessed from views.
80 | */
81 | @Extension
82 | // This indicates to Jenkins that this is an implementation of an extension
83 | // point.
84 | public static final class DescriptorImpl extends
85 | TimedBuildStepDescriptor {
86 |
87 | public FormValidation doCheckBldCfg(@QueryParameter String value)
88 | throws IOException, ServletException {
89 | return ParamVerify.doCheckBldCfg(value);
90 | }
91 |
92 | public String getDisplayName() {
93 | return DISPLAY_NAME;
94 | }
95 |
96 | @Override
97 | protected long getStaticDefaultWaitTime() {
98 | return GlobalConfig.DEFAULT_BUILD_WAIT;
99 | }
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/OpenShiftApiObjHandler.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public class OpenShiftApiObjHandler {
7 | // POST https://localhost:8443/apis/extensions/v1beta1/namespaces/test/jobs
8 | // POST https://localhost:8443/oapi/v1/namespaces/test/imagestreams
9 | public final static String api = "/api";
10 | public final static String oapi = "/oapi";
11 | public final static String apis = "/apis";
12 |
13 | public static final Map typeShortcut;
14 | public static final Map apiMap;
15 | static {
16 | // a starter set of API endpoints, which will be updated via calls
17 | // to fetchApiJsonFromGithub(boolean, TaskListener, Map,
18 | // String)
19 | // and importJsonOfApiTypes(boolean, TaskListener, Map,
20 | // String, String)
21 |
22 | // OpenShift API endpoints
23 | apiMap = new HashMap();
24 | apiMap.put("BuildConfig", new String[] { oapi, "buildconfigs" });
25 | apiMap.put("Build", new String[] { oapi, "builds" });
26 | apiMap.put("DeploymentConfigRollback", new String[] { oapi,
27 | "deploymentconfigrollbacks" });
28 | apiMap.put("DeploymentConfig",
29 | new String[] { oapi, "deploymentconfigs" });
30 | apiMap.put("ImageStreamMapping", new String[] { oapi,
31 | "imagestreammappings" });
32 | apiMap.put("ImageStream", new String[] { oapi, "imagestreams" });
33 | apiMap.put("LocalResourceAccessReview", new String[] { oapi,
34 | "localresourceaccessreviews" });
35 | apiMap.put("LocalSubjectAccessReview", new String[] { oapi,
36 | "localsubjectaccessreviews" });
37 | apiMap.put("Policy", new String[] { oapi, "policies" });
38 | apiMap.put("PolicyBinding", new String[] { oapi, "policybindings" });
39 | // apiMap.put("Template", new String[]{oapi, "processedtemplates"}); //
40 | // Different from templates?
41 | apiMap.put("ResourceAccessReview", new String[] { oapi,
42 | "resourceaccessreviews" });
43 | apiMap.put("RoleBinding", new String[] { oapi, "rolebindings" });
44 | apiMap.put("Role", new String[] { oapi, "roles" });
45 | apiMap.put("Route", new String[] { oapi, "routes" });
46 | apiMap.put("SubjectAccessReview", new String[] { oapi,
47 | "subjectaccessreviews" });
48 | apiMap.put("Template", new String[] { oapi, "templates" });
49 |
50 | // Kubernetes API endpoints
51 | apiMap.put("Binding", new String[] { api, "bindings" });
52 | apiMap.put("Endpoint", new String[] { api, "endpoints" });
53 | apiMap.put("Event", new String[] { api, "events" });
54 | apiMap.put("LimitRange", new String[] { api, "limitranges" });
55 | apiMap.put("PersistentVolumeClaim", new String[] { api,
56 | "persistentvolumeclaims" });
57 | apiMap.put("Pod", new String[] { api, "pods" });
58 | apiMap.put("PodTemplate", new String[] { api, "podtemplates" });
59 | apiMap.put("ReplicationController", new String[] { api,
60 | "replicationcontrollers" });
61 | apiMap.put("ResourceQuota", new String[] { api, "resourcequotas" });
62 | apiMap.put("Secret", new String[] { api, "secrets" });
63 | apiMap.put("ServiceAccount", new String[] { api, "serviceaccounts" });
64 | apiMap.put("Service", new String[] { api, "services" });
65 | apiMap.put("Job", new String[] { apis, "jobs" });
66 |
67 | typeShortcut = new HashMap();
68 | typeShortcut.put("build", "Build");
69 | typeShortcut.put("bc", "BuildConfig");
70 | typeShortcut.put("dc", "DeploymentConfig");
71 | typeShortcut.put("is", "ImageStream");
72 | typeShortcut.put("istag", "ImageStreamTag");
73 | typeShortcut.put("route", "Route");
74 | typeShortcut.put("rc", "ReplicationController");
75 | typeShortcut.put("secret", "Secret");
76 | typeShortcut.put("svc", "Service");
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/model/IOpenShiftServiceVerifier.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline.model;
2 |
3 | import com.openshift.jenkins.plugins.pipeline.MessageConstants;
4 | import com.openshift.restclient.IClient;
5 | import com.openshift.restclient.ResourceKind;
6 | import com.openshift.restclient.model.IService;
7 | import hudson.Launcher;
8 | import hudson.model.TaskListener;
9 |
10 | import java.io.IOException;
11 | import java.net.InetSocketAddress;
12 | import java.net.Socket;
13 | import java.util.Map;
14 |
15 | public interface IOpenShiftServiceVerifier extends IOpenShiftPlugin {
16 | String DISPLAY_NAME = "Verify OpenShift Service";
17 |
18 | default String getDisplayName() {
19 | return DISPLAY_NAME;
20 | }
21 |
22 | String getSvcName();
23 |
24 | String getRetryCount();
25 |
26 | String getRetryCount(Map overrides);
27 |
28 | default String getSvcName(Map overrides) {
29 | return getOverride(getSvcName(), overrides);
30 | }
31 |
32 | default boolean coreLogic(Launcher launcher, TaskListener listener,
33 | Map overrides) {
34 | boolean chatty = Boolean.parseBoolean(getVerbose(overrides));
35 | listener.getLogger().println(
36 | String.format(MessageConstants.START_SERVICE_VERIFY,
37 | DISPLAY_NAME, getSvcName(overrides),
38 | getNamespace(overrides)));
39 |
40 | // get oc client
41 | IClient client = this.getClient(listener, DISPLAY_NAME, overrides);
42 | String spec = null;
43 |
44 | if (client != null) {
45 | // get Service
46 | IService svc = client.get(ResourceKind.SERVICE,
47 | getSvcName(overrides), getNamespace(overrides));
48 | String ip = svc.getClusterIP();
49 | int port = svc.getPort();
50 | spec = ip + ":" + port;
51 | int tryCount = 0;
52 | if (chatty)
53 | listener.getLogger().println(
54 | "\nOpenShiftServiceVerifier retry "
55 | + getRetryCount(overrides));
56 | listener.getLogger().println(
57 | String.format(MessageConstants.SERVICE_CONNECTING, spec));
58 | while (tryCount < Integer.parseInt(getRetryCount(overrides))) {
59 | tryCount++;
60 | if (chatty)
61 | listener.getLogger().println(
62 | "\nOpenShiftServiceVerifier attempt connect to "
63 | + spec + " attempt " + tryCount);
64 | InetSocketAddress address = new InetSocketAddress(ip, port);
65 | Socket socket = null;
66 | try {
67 | socket = new Socket();
68 | socket.connect(address, 2500);
69 | listener.getLogger().println(
70 | String.format(
71 | MessageConstants.EXIT_SERVICE_VERIFY_GOOD,
72 | DISPLAY_NAME, spec));
73 | return true;
74 | } catch (IOException e) {
75 | if (chatty)
76 | e.printStackTrace(listener.getLogger());
77 | try {
78 | Thread.sleep(2500);
79 | } catch (InterruptedException e1) {
80 | }
81 | } finally {
82 | try {
83 | socket.close();
84 | } catch (IOException e) {
85 | if (chatty)
86 | e.printStackTrace(listener.getLogger());
87 | }
88 | }
89 | }
90 |
91 | } else {
92 | return false;
93 | }
94 |
95 | listener.getLogger().println(
96 | String.format(MessageConstants.EXIT_SERVICE_VERIFY_BAD,
97 | DISPLAY_NAME, spec));
98 |
99 | return false;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/OpenShiftDeleterJsonYaml.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline;
2 |
3 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftDeleterJsonYaml;
4 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftPluginDescriptor;
5 | import hudson.Extension;
6 | import hudson.model.AbstractProject;
7 | import hudson.tasks.BuildStepDescriptor;
8 | import hudson.tasks.Builder;
9 | import hudson.util.FormValidation;
10 | import net.sf.json.JSONObject;
11 | import org.kohsuke.stapler.DataBoundConstructor;
12 | import org.kohsuke.stapler.QueryParameter;
13 | import org.kohsuke.stapler.StaplerRequest;
14 |
15 | import javax.servlet.ServletException;
16 | import java.io.IOException;
17 |
18 | public class OpenShiftDeleterJsonYaml extends OpenShiftBaseStep implements
19 | IOpenShiftDeleterJsonYaml {
20 |
21 | protected final String jsonyaml;
22 |
23 | // Fields in config.jelly must match the parameter names in the
24 | // "DataBoundConstructor"
25 | @DataBoundConstructor
26 | public OpenShiftDeleterJsonYaml(String apiURL, String namespace,
27 | String authToken, String verbose, String jsonyaml) {
28 | super(apiURL, namespace, authToken, verbose);
29 | this.jsonyaml = jsonyaml != null ? jsonyaml.trim() : null;
30 | }
31 |
32 | // generically speaking, Jenkins will always pass in non-null field values.
33 | // However, as we have periodically
34 | // added new fields, jobs created with earlier versions of the plugin get
35 | // null for the new fields. Hence,
36 | // we have introduced the generic convention (even for fields that existed
37 | // in the initial incarnations of the plugin)
38 | // of insuring nulls are not returned for field getters
39 |
40 | public String getJsonyaml() {
41 | return jsonyaml;
42 | }
43 |
44 | // Overridden for better type safety.
45 | // If your plugin doesn't really define any property on Descriptor,
46 | // you don't have to do this.
47 | @Override
48 | public DescriptorImpl getDescriptor() {
49 | return (DescriptorImpl) super.getDescriptor();
50 | }
51 |
52 | /**
53 | * Descriptor for {@link OpenShiftDeleterJsonYaml}. Used as a singleton. The
54 | * class is marked as public so that it can be accessed from views.
55 | *
56 | */
57 | @Extension
58 | // This indicates to Jenkins that this is an implementation of an extension
59 | // point.
60 | public static final class DescriptorImpl extends
61 | BuildStepDescriptor implements IOpenShiftPluginDescriptor {
62 | /**
63 | * To persist global configuration information, simply store it in a
64 | * field and call save().
65 | *
66 | *
67 | * If you don't want fields to be persisted, use transient.
68 | */
69 |
70 | /**
71 | * In order to load the persisted global configuration, you have to call
72 | * load() in the constructor.
73 | */
74 | public DescriptorImpl() {
75 | load();
76 | }
77 |
78 | public FormValidation doCheckJsonyaml(@QueryParameter String value)
79 | throws IOException, ServletException {
80 | return ParamVerify.doCheckJsonyaml(value);
81 | }
82 |
83 | public boolean isApplicable(Class extends AbstractProject> aClass) {
84 | // Indicates that this builder can be used with all kinds of project
85 | // types
86 | return true;
87 | }
88 |
89 | /**
90 | * This human readable name is used in the configuration screen.
91 | */
92 | public String getDisplayName() {
93 | return DISPLAY_NAME;
94 | }
95 |
96 | @Override
97 | public boolean configure(StaplerRequest req, JSONObject formData)
98 | throws FormException {
99 | // To persist global configuration information,
100 | // pull info from formData, set appropriate instance field (which
101 | // should have a getter), and call save().
102 | save();
103 | return super.configure(req, formData);
104 | }
105 |
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/model/IOpenShiftDeleterJsonYaml.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline.model;
2 |
3 | import hudson.Launcher;
4 | import hudson.model.TaskListener;
5 |
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | import org.jboss.dmr.ModelNode;
10 |
11 | import com.openshift.jenkins.plugins.pipeline.MessageConstants;
12 | import com.openshift.restclient.IClient;
13 |
14 | public interface IOpenShiftDeleterJsonYaml extends IOpenShiftApiObjHandler {
15 |
16 | final static String DISPLAY_NAME = "Delete OpenShift Resource(s) from JSON or YAML";
17 | final static String UNDEFINED = "undefined";
18 |
19 | default String getDisplayName() {
20 | return DISPLAY_NAME;
21 | }
22 |
23 | String getJsonyaml();
24 |
25 | default String getJsonyaml(Map overrides) {
26 | return getOverride(getJsonyaml(), overrides);
27 | }
28 |
29 | default boolean coreLogic(Launcher launcher, TaskListener listener,
30 | Map overrides) {
31 | boolean chatty = Boolean.parseBoolean(getVerbose(overrides));
32 | listener.getLogger().println(
33 | String.format(MessageConstants.START_DELETE_OBJS, DISPLAY_NAME,
34 | getNamespace(overrides)));
35 | updateApiTypes(chatty, listener, overrides);
36 |
37 | ModelNode resources = this.hydrateJsonYaml(getJsonyaml(overrides),
38 | chatty ? listener : null);
39 | if (resources == null) {
40 | return false;
41 | }
42 |
43 | // get oc client
44 | IClient client = this.getClient(listener, DISPLAY_NAME, overrides);
45 |
46 | if (client != null) {
47 | // cycle through json and POST to appropriate resource
48 | String kind = resources.get("kind").asString();
49 | int deletes = 0;
50 | int fails = 0;
51 | if (kind.equalsIgnoreCase("List")) {
52 | List list = resources.get("items").asList();
53 | for (ModelNode node : list) {
54 | String path = node.get("kind").asString();
55 | String name = node.get("metadata").get("name").asString();
56 | String namespace = node.get("metadata").get("namespace")
57 | .asString();
58 | if (UNDEFINED.equals(namespace))
59 | namespace = getNamespace(overrides);
60 |
61 | // rc[0] will be successful deletes, rc[1] will be failed
62 | // deletes
63 | int[] rc = new int[2];
64 | rc = deleteAPIObjs(client, listener, namespace, path, name,
65 | null, chatty);
66 | deletes = deletes + rc[0];
67 | fails = fails + rc[1];
68 |
69 | }
70 | } else {
71 | String path = kind;
72 | String name = resources.get("metadata").get("name").asString();
73 | String namespace = resources.get("metadata").get("namespace")
74 | .asString();
75 | if (UNDEFINED.equals(namespace))
76 | namespace = getNamespace(overrides);
77 |
78 | // rc[0] will be successful deletes, rc[1] will be failed
79 | // deletes
80 | int[] rc = new int[2];
81 | rc = deleteAPIObjs(client, listener, namespace, path, name,
82 | null, chatty);
83 | deletes = deletes + rc[0];
84 | fails = fails + rc[1];
85 |
86 | }
87 |
88 | if (fails > 0) {
89 | listener.getLogger().println(
90 | String.format(MessageConstants.EXIT_DELETE_BAD,
91 | DISPLAY_NAME, deletes, fails));
92 | return false;
93 | } else {
94 | listener.getLogger().println(
95 | String.format(MessageConstants.EXIT_DELETE_GOOD,
96 | DISPLAY_NAME, deletes));
97 | return true;
98 | }
99 | }
100 | return false;
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/RELEASING.md:
--------------------------------------------------------------------------------
1 | # Process for cutting release of this plugin
2 |
3 | As noted in this repository's README.md, the documentation and code at [https://github.com/openshift/jenkins-plugin](https://github.com/openshift/jenkins-plugin) always hosts the very latest version, including possibly pre-released versions that are still under test.
4 | The associated repository under the JenkinsCI project, [https://github.com/jenkinsci/openshift-pipeline-plugin](https://github.com/jenkinsci/openshift-pipeline-plugin), is only updated as part of cutting
5 | official releases of this plugin.
6 |
7 | To cut a new release of this plugin, first perform a `git clone` of [https://github.com/jenkinsci/openshift-pipeline-plugin](https://github.com/jenkinsci/openshift-pipeline-plugin),
8 |
9 | ## Set up local repository to cut release:
10 |
11 | 1. From the parent directory you've chosen for you local repository, run `git clone git@github.com:jenkinsci/openshift-pipeline-plugin.git`
12 | 1. Change directories into `openshift-pipeline-plugin`, and run `git remote add upstream git://github.com/openshift/jenkins-plugin`
13 | 1. Then pull the latest changes from [https://github.com/openshift/jenkins-plugin](https://github.com/openshift/jenkins-plugin) with the following:
14 |
15 | ```
16 | $ git checkout master
17 | $ git fetch upstream
18 | $ git fetch upstream --tags
19 | $ git rebase upstream/master
20 | $ git push origin master
21 | $ git push origin --tags
22 | ```
23 |
24 | ## Submit the new release to the Jenkins organization
25 |
26 | Assumptions: your Git ID has push access to the two repositories for this plugin; your Jenkins ID (https://wiki.jenkins-ci.org/display/JENKINS/User+Account+on+Jenkins) is listed in https://github.com/jenkins-infra/repository-permissions-updater/blob/master/permissions/plugin-openshift-pipeline.yml. Given these assumptions:
27 |
28 | 1. Then run `mvn release:prepare release:perform`
29 | 1. You'll minimally be prompted for the `release version`, `release tag`, and the `new development version`. Default choices will be provided for each, and the defaults are typically acceptable, so you can just hit the enter key for all three prompts. As an example, if we are currently at v1.0.36, it will provide 1.0.37 for the new `release version` and `release tag`. For the `new development version` it will provide 1.0.38-SNAPSHOT, which is again acceptable. The only time you *might* have to override the default provided is if we currently depend on a SNAPSHOT version of openshift-restclient-java (e.g. `5.3.0-SNAPSHOT`). This occurs when we add new features to openshift-restclient-java, but the eclipse team has not cut a new, official release (which will typically look like `5.3.0-FINAL`). If we are in such a mode, you'll get prompted about moving off the SNAPSHOT version (the default provided would be `5.3.0`), but override this (i.e. type in `5.3.0-SNAPSHOT`).
30 | 1. The `mvn release:prepare release:perform` command will take a few minutes to build the plugin and go through various verifications, followed by a push of the built artifacts up to Jenkins. This typically works without further involvement but has failed for various reasons in the past. If so, to retry with the same release version, you'll need to call `git reset` to back of the two commits created as part of publishing the release, as well as use `git tag` to delete both the local and remote version of the corresponding tag. After deleting the commits and tags, use `git push -f` to update the commits at [https://github.com/jenkinsci/openshift-pipeline-plugin](https://github.com/jenkinsci/openshift-pipeline-plugin). Address whatever issues you have (you might have to solicit help on the Jenkins developer group: https://groups.google.com/forum/#!forum/jenkinsci-dev) and try again.
31 | 1. Run `git push https://github.com/openshift/jenkins-plugin.git master` to upload the 2 commits created for cutting the new release to our upstream, development repository, and get the two repositories back in sync.
32 | 1. Monitor https://updates.jenkins-ci.org/download/plugins/openshift-pipeline/ for the existence of the new version of the plugin. Warning: the link for the new version will show up, but does not mean the `openshift-pipeline.hpi` file is available yet. Click the link to confirm you can download the new version of the plugin. When you can download the latest `openshift-pipeline.hpi` file, the process is complete, and the new release is available.
33 |
34 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/dsl/OpenShiftBuildVerifier.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline.dsl;
2 |
3 | import com.openshift.jenkins.plugins.pipeline.ParamVerify;
4 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftBuildVerifier;
5 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftPluginDescriptor;
6 | import hudson.Extension;
7 | import hudson.model.AbstractBuild;
8 | import hudson.model.AbstractProject;
9 | import hudson.model.Action;
10 | import hudson.model.BuildListener;
11 | import hudson.tasks.BuildStepMonitor;
12 | import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
13 | import org.jenkinsci.plugins.workflow.steps.Step;
14 | import org.kohsuke.stapler.DataBoundConstructor;
15 | import org.kohsuke.stapler.DataBoundSetter;
16 |
17 | import java.util.Collection;
18 | import java.util.Map;
19 |
20 | public class OpenShiftBuildVerifier extends TimedOpenShiftBaseStep implements
21 | IOpenShiftBuildVerifier {
22 |
23 | protected final String bldCfg;
24 | protected String checkForTriggeredDeployments;
25 |
26 | @DataBoundConstructor
27 | public OpenShiftBuildVerifier(String bldCfg) {
28 | this.bldCfg = bldCfg != null ? bldCfg.trim() : null;
29 | }
30 |
31 | @Override
32 | public boolean prebuild(AbstractBuild, ?> build, BuildListener listener) {
33 | return true;
34 | }
35 |
36 | @Override
37 | public Action getProjectAction(AbstractProject, ?> project) {
38 | return null;
39 | }
40 |
41 | @Override
42 | public Collection extends Action> getProjectActions(
43 | AbstractProject, ?> project) {
44 | return null;
45 | }
46 |
47 | @Override
48 | public BuildStepMonitor getRequiredMonitorService() {
49 | return null;
50 | }
51 |
52 | @Override
53 | public String getBldCfg() {
54 | return bldCfg;
55 | }
56 |
57 | @Override
58 | public String getCheckForTriggeredDeployments() {
59 | return checkForTriggeredDeployments;
60 | }
61 |
62 | @DataBoundSetter
63 | public void setCheckForTriggeredDeployments(
64 | String checkForTriggeredDeployments) {
65 | this.checkForTriggeredDeployments = checkForTriggeredDeployments != null ? checkForTriggeredDeployments
66 | .trim() : null;
67 | }
68 |
69 | @Extension
70 | public static class DescriptorImpl extends AbstractStepDescriptorImpl
71 | implements IOpenShiftPluginDescriptor {
72 |
73 | public DescriptorImpl() {
74 | super(OpenShiftBuildVerifierExecution.class);
75 | }
76 |
77 | @Override
78 | public String getFunctionName() {
79 | return "openshiftVerifyBuild";
80 | }
81 |
82 | @Override
83 | public String getDisplayName() {
84 | return DISPLAY_NAME;
85 | }
86 |
87 | @Override
88 | public Step newInstance(Map arguments) throws Exception {
89 | if (!arguments.containsKey("buildConfig")
90 | && !arguments.containsKey("bldCfg"))
91 | throw new IllegalArgumentException(
92 | "need to specify buildConfig");
93 | Object bldCfg = arguments.get("buildConfig");
94 | if (bldCfg == null || bldCfg.toString().trim().length() == 0)
95 | bldCfg = arguments.get("bldCfg");
96 | if (bldCfg == null || bldCfg.toString().trim().length() == 0)
97 | throw new IllegalArgumentException(
98 | "need to specify buildConfig");
99 | OpenShiftBuildVerifier step = new OpenShiftBuildVerifier(
100 | bldCfg.toString());
101 | if (arguments.containsKey("checkForTriggeredDeployments")) {
102 | Object checkForTriggeredDeployments = arguments
103 | .get("checkForTriggeredDeployments");
104 | if (checkForTriggeredDeployments != null) {
105 | step.setCheckForTriggeredDeployments(checkForTriggeredDeployments
106 | .toString());
107 | }
108 | }
109 |
110 | ParamVerify.updateTimedDSLBaseStep(arguments, step);
111 | return step;
112 | }
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/model/IOpenShiftDeleterList.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline.model;
2 |
3 | import hudson.Launcher;
4 | import hudson.model.TaskListener;
5 |
6 | import java.util.Map;
7 | import java.util.Set;
8 |
9 | import com.openshift.jenkins.plugins.pipeline.MessageConstants;
10 | import com.openshift.jenkins.plugins.pipeline.OpenShiftApiObjHandler;
11 | import com.openshift.restclient.IClient;
12 |
13 | public interface IOpenShiftDeleterList extends IOpenShiftApiObjHandler {
14 |
15 | final static String DISPLAY_NAME = "Delete OpenShift Resource(s) by Key";
16 |
17 | default String getDisplayName() {
18 | return DISPLAY_NAME;
19 | }
20 |
21 | String getKeys();
22 |
23 | String getTypes();
24 |
25 | default String getTypes(Map overrides) {
26 | return getOverride(getTypes(), overrides);
27 | }
28 |
29 | default String getKeys(Map overrides) {
30 | return getOverride(getKeys(), overrides);
31 | }
32 |
33 | default boolean coreLogic(Launcher launcher, TaskListener listener,
34 | Map overrides) {
35 | boolean chatty = Boolean.parseBoolean(getVerbose(overrides));
36 | listener.getLogger().println(
37 | String.format(MessageConstants.START_DELETE_OBJS, DISPLAY_NAME,
38 | getNamespace(overrides)));
39 |
40 | updateApiTypes(chatty, listener, overrides);
41 |
42 | // get oc client
43 | IClient client = this.getClient(listener, DISPLAY_NAME, overrides);
44 |
45 | if (client != null) {
46 | // verify valid type is specified
47 | Set types = OpenShiftApiObjHandler.apiMap.keySet();
48 | String resourceKind = null;
49 | int deletes = 0;
50 | int fails = 0;
51 | int badType = 0;
52 | String[] inputTypes = getTypes(overrides).split(",");
53 | String[] inputKeys = getKeys(overrides).split(",");
54 |
55 | if (inputTypes.length != inputKeys.length) {
56 | listener.getLogger().println(
57 | String.format(
58 | MessageConstants.EXIT_DELETE_KEY_TYPE_MISMATCH,
59 | inputTypes.length, inputKeys.length));
60 | return false;
61 | }
62 |
63 | for (int i = 0; i < inputTypes.length; i++) {
64 | if (OpenShiftApiObjHandler.typeShortcut
65 | .containsKey(inputTypes[i])) {
66 | resourceKind = OpenShiftApiObjHandler.typeShortcut
67 | .get(inputTypes[i]);
68 | } else {
69 | for (String type : types) {
70 |
71 | if (type.equalsIgnoreCase(inputTypes[i])) {
72 | resourceKind = type;
73 | break;
74 | }
75 |
76 | }
77 | }
78 |
79 | if (resourceKind == null) {
80 | listener.getLogger().println(
81 | String.format(MessageConstants.TYPE_NOT_SUPPORTED,
82 | inputTypes[i]));
83 | badType++;
84 | continue;
85 | }
86 |
87 | // rc[0] will be successful deletes, rc[1] will be failed
88 | // deletes
89 | int[] rc = new int[2];
90 | rc = deleteAPIObjs(client, listener, getNamespace(overrides),
91 | resourceKind, inputKeys[i], null, chatty);
92 | deletes = deletes + rc[0];
93 | fails = fails + rc[1];
94 | }
95 |
96 | if (fails == 0 && badType == 0) {
97 | listener.getLogger().println(
98 | String.format(MessageConstants.EXIT_DELETE_GOOD,
99 | DISPLAY_NAME, deletes));
100 | return true;
101 | } else {
102 | listener.getLogger().println(
103 | String.format(MessageConstants.EXIT_DELETE_BAD,
104 | DISPLAY_NAME, deletes, fails + badType));
105 | }
106 | }
107 | return false;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/dsl/OpenShiftServiceVerifier.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline.dsl;
2 |
3 | import com.openshift.jenkins.plugins.pipeline.ParamVerify;
4 | import com.openshift.jenkins.plugins.pipeline.model.GlobalConfig;
5 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftPluginDescriptor;
6 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftServiceVerifier;
7 | import hudson.Extension;
8 | import hudson.model.AbstractBuild;
9 | import hudson.model.AbstractProject;
10 | import hudson.model.Action;
11 | import hudson.model.BuildListener;
12 | import hudson.tasks.BuildStepMonitor;
13 | import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
14 | import org.jenkinsci.plugins.workflow.steps.Step;
15 | import org.kohsuke.stapler.DataBoundConstructor;
16 | import org.kohsuke.stapler.DataBoundSetter;
17 |
18 | import java.util.Collection;
19 | import java.util.Map;
20 | import java.util.logging.Logger;
21 |
22 | public class OpenShiftServiceVerifier extends OpenShiftBaseStep implements
23 | IOpenShiftServiceVerifier {
24 |
25 | protected final String svcName;
26 | protected String retryCount;
27 |
28 | @DataBoundConstructor
29 | public OpenShiftServiceVerifier(String svcName) {
30 | this.svcName = svcName != null ? svcName.trim() : null;
31 | }
32 |
33 | public String getSvcName() {
34 | return svcName;
35 | }
36 |
37 | public String getSvcName(Map overrides) {
38 | return getSvcName();
39 | }
40 |
41 | public String getRetryCount() {
42 | return retryCount;
43 | }
44 |
45 | public String getRetryCount(Map overrides) {
46 | String val = getOverride(getRetryCount(), overrides);
47 | if (val.length() > 0)
48 | return val;
49 | return Integer.toString(GlobalConfig.getServiceVerifyRetry());
50 | }
51 |
52 | @DataBoundSetter
53 | public void setRetryCount(String retryCount) {
54 | this.retryCount = retryCount != null ? retryCount.trim() : null;
55 | }
56 |
57 | @Override
58 | public boolean prebuild(AbstractBuild, ?> build, BuildListener listener) {
59 | return true;
60 | }
61 |
62 | @Override
63 | public Action getProjectAction(AbstractProject, ?> project) {
64 | return null;
65 | }
66 |
67 | @Override
68 | public Collection extends Action> getProjectActions(
69 | AbstractProject, ?> project) {
70 | return null;
71 | }
72 |
73 | @Override
74 | public BuildStepMonitor getRequiredMonitorService() {
75 | return null;
76 | }
77 |
78 | private static final Logger LOGGER = Logger
79 | .getLogger(OpenShiftServiceVerifier.class.getName());
80 |
81 | @Extension
82 | public static class DescriptorImpl extends AbstractStepDescriptorImpl
83 | implements IOpenShiftPluginDescriptor {
84 |
85 | public DescriptorImpl() {
86 | super(OpenShiftServiceVerifierExecution.class);
87 | }
88 |
89 | @Override
90 | public String getFunctionName() {
91 | return "openshiftVerifyService";
92 | }
93 |
94 | @Override
95 | public String getDisplayName() {
96 | return DISPLAY_NAME;
97 | }
98 |
99 | @Override
100 | public Step newInstance(Map arguments) throws Exception {
101 | if (!arguments.containsKey("serviceName")
102 | && !arguments.containsKey("svcName"))
103 | throw new IllegalArgumentException(
104 | "need to specify serviceName");
105 | Object svcName = arguments.get("serviceName");
106 | if (svcName == null || svcName.toString().trim().length() == 0)
107 | svcName = arguments.get("svcName");
108 | if (svcName == null || svcName.toString().trim().length() == 0)
109 | throw new IllegalArgumentException(
110 | "need to specify serviceName");
111 | OpenShiftServiceVerifier step = new OpenShiftServiceVerifier(
112 | svcName.toString());
113 |
114 | if (arguments.containsKey("retryCount")) {
115 | Object retryCount = arguments.get("retryCount");
116 | if (retryCount != null)
117 | step.setRetryCount(retryCount.toString());
118 | }
119 |
120 | ParamVerify.updateDSLBaseStep(arguments, step);
121 | return step;
122 | }
123 | }
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/dsl/OpenShiftScaler.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline.dsl;
2 |
3 | import com.openshift.jenkins.plugins.pipeline.ParamVerify;
4 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftPluginDescriptor;
5 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftScaler;
6 | import hudson.Extension;
7 | import hudson.model.AbstractBuild;
8 | import hudson.model.AbstractProject;
9 | import hudson.model.Action;
10 | import hudson.model.BuildListener;
11 | import hudson.tasks.BuildStepMonitor;
12 | import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
13 | import org.jenkinsci.plugins.workflow.steps.Step;
14 | import org.kohsuke.stapler.DataBoundConstructor;
15 | import org.kohsuke.stapler.DataBoundSetter;
16 |
17 | import java.util.Collection;
18 | import java.util.Map;
19 | import java.util.logging.Logger;
20 |
21 | public class OpenShiftScaler extends TimedOpenShiftBaseStep implements
22 | IOpenShiftScaler {
23 |
24 | protected final String depCfg;
25 | protected final String replicaCount;
26 | protected String verifyReplicaCount;
27 |
28 | @DataBoundConstructor
29 | public OpenShiftScaler(String depCfg, String replicaCount) {
30 | this.depCfg = depCfg != null ? depCfg.trim() : null;
31 | this.replicaCount = replicaCount != null ? replicaCount.trim() : null;
32 | }
33 |
34 | public String getDepCfg() {
35 | return depCfg;
36 | }
37 |
38 | public String getReplicaCount() {
39 | return replicaCount;
40 | }
41 |
42 | public String getVerifyReplicaCount() {
43 | return verifyReplicaCount;
44 | }
45 |
46 | @DataBoundSetter
47 | public void setVerifyReplicaCount(String verifyReplicaCount) {
48 | this.verifyReplicaCount = verifyReplicaCount != null ? verifyReplicaCount
49 | .trim() : null;
50 | }
51 |
52 | @Override
53 | public boolean prebuild(AbstractBuild, ?> build, BuildListener listener) {
54 | return true;
55 | }
56 |
57 | @Override
58 | public Action getProjectAction(AbstractProject, ?> project) {
59 | return null;
60 | }
61 |
62 | @Override
63 | public Collection extends Action> getProjectActions(
64 | AbstractProject, ?> project) {
65 | return null;
66 | }
67 |
68 | @Override
69 | public BuildStepMonitor getRequiredMonitorService() {
70 | return null;
71 | }
72 |
73 | private static final Logger LOGGER = Logger.getLogger(OpenShiftScaler.class
74 | .getName());
75 |
76 | @Extension
77 | public static class DescriptorImpl extends AbstractStepDescriptorImpl
78 | implements IOpenShiftPluginDescriptor {
79 |
80 | public DescriptorImpl() {
81 | super(OpenShiftScalerExecution.class);
82 | }
83 |
84 | @Override
85 | public String getFunctionName() {
86 | return "openshiftScale";
87 | }
88 |
89 | @Override
90 | public String getDisplayName() {
91 | return DISPLAY_NAME;
92 | }
93 |
94 | @Override
95 | public Step newInstance(Map arguments) throws Exception {
96 | if (!arguments.containsKey("deploymentConfig")
97 | && !arguments.containsKey("depCfg"))
98 | throw new IllegalArgumentException(
99 | "need to specify deploymentConfig");
100 | Object depCfg = arguments.get("deploymentConfig");
101 | if (depCfg == null || depCfg.toString().trim().length() == 0)
102 | depCfg = arguments.get("depCfg");
103 | if (depCfg == null || depCfg.toString().trim().length() == 0)
104 | throw new IllegalArgumentException(
105 | "need to specify deploymentConfig");
106 | if (!arguments.containsKey("replicaCount"))
107 | throw new IllegalArgumentException(
108 | "need to specif replicaCount");
109 | OpenShiftScaler step = new OpenShiftScaler(depCfg.toString(),
110 | arguments.get("replicaCount").toString());
111 |
112 | if (arguments.containsKey("verifyReplicaCount")) {
113 | Object verifyReplicaCount = arguments.get("verifyReplicaCount");
114 | if (verifyReplicaCount != null)
115 | step.setVerifyReplicaCount(verifyReplicaCount.toString());
116 | }
117 |
118 | ParamVerify.updateTimedDSLBaseStep(arguments, step);
119 | return step;
120 | }
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/TimedBuildStepDescriptor.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline;
2 |
3 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftPluginDescriptor;
4 | import com.openshift.jenkins.plugins.pipeline.model.ITimedOpenShiftPlugin;
5 | import hudson.model.AbstractProject;
6 | import hudson.model.Describable;
7 | import hudson.tasks.BuildStep;
8 | import hudson.tasks.BuildStepDescriptor;
9 | import net.sf.json.JSONObject;
10 | import org.kohsuke.stapler.StaplerRequest;
11 |
12 | /**
13 | * Extending this descriptor imbues subclasses with a global Jenkins timeout
14 | * setting.
15 | *
16 | * Theory of operation: 1. Each timed operation which exposes a global timeout
17 | * extends this descriptor. 2. The descriptor will persist/restore a global
18 | * wait/waitUnit for the operation type. 3. Classes wishing to share the same
19 | * timeout value (e.g. DSL steps) should access the timeout value through
20 | * GlobalConfig. 4. GlobalConfig will load the correct descriptor to read the
21 | * currently configured timeout value. 5. The host for the global config option
22 | * must have a global.jelly for setting the value from Jenkins Configure. See
23 | * examples like:
24 | * src/main/resources/com/openshift/jenkins/plugins/pipeline/OpenShiftExec
25 | * /global.jelly
26 | */
27 | public abstract class TimedBuildStepDescriptor>
28 | extends BuildStepDescriptor implements IOpenShiftPluginDescriptor {
29 |
30 | protected String wait;
31 | protected String waitUnit;
32 |
33 | TimedBuildStepDescriptor() {
34 | load();
35 | }
36 |
37 | @Override
38 | public synchronized void load() {
39 | super.load();
40 | if (wait == null || wait.trim().isEmpty()) {
41 | wait = "" + getStaticDefaultWaitTime();
42 | }
43 |
44 | long w = Long.parseLong(wait);
45 |
46 | if (waitUnit == null || waitUnit.trim().isEmpty()) {
47 | if (w > 1000
48 | && (w
49 | % ITimedOpenShiftPlugin.TimeoutUnit.SECONDS.multiplier == 0)) {
50 | // We are loading a new or an existing config without time units
51 | waitUnit = ITimedOpenShiftPlugin.TimeoutUnit.SECONDS.name;
52 | // Convert existing timeout to seconds
53 | w /= ITimedOpenShiftPlugin.TimeoutUnit.SECONDS.multiplier;
54 | } else {
55 | waitUnit = ITimedOpenShiftPlugin.TimeoutUnit.MILLISECONDS.name;
56 | }
57 | }
58 |
59 | wait = "" + w;
60 | }
61 |
62 | @Override
63 | public boolean isApplicable(Class extends AbstractProject> aClass) {
64 | // Indicates that this builder can be used with all kinds of project
65 | // types
66 | return true;
67 | }
68 |
69 | @Override
70 | public synchronized boolean configure(StaplerRequest req,
71 | JSONObject formData) throws FormException {
72 | wait = formData.getString("wait");
73 | waitUnit = ITimedOpenShiftPlugin.TimeoutUnit.normalize(formData
74 | .getString("waitUnit"));
75 | if (wait == null || wait.isEmpty()) {
76 | // If someone clears the value, go back to default and use seconds
77 | wait = "" + getStaticDefaultWaitTime()
78 | / ITimedOpenShiftPlugin.TimeoutUnit.SECONDS.multiplier;
79 | waitUnit = ITimedOpenShiftPlugin.TimeoutUnit.SECONDS.name;
80 | }
81 | wait = wait.trim();
82 | save();
83 | return true;
84 | }
85 |
86 | public synchronized long getConfiguredDefaultWaitTime() {
87 | ITimedOpenShiftPlugin.TimeoutUnit unit = ITimedOpenShiftPlugin.TimeoutUnit
88 | .getByName(waitUnit);
89 | return unit.toMilliseconds("" + wait, getStaticDefaultWaitTime());
90 | }
91 |
92 | public synchronized String getWait() {
93 | return wait;
94 | }
95 |
96 | public synchronized String getWaitUnit() {
97 | return waitUnit;
98 | }
99 |
100 | /**
101 | * @return Return the non-configurable default for this build step. This
102 | * will populate the global default wait time for the operation the
103 | * first time Jenkins loads this plugin. Once a global configuration
104 | * with a value exists, this value will no longer be used. However,
105 | * this value will be re-populated if the user clears the global
106 | * timeout form and saves the configuration.
107 | */
108 | protected abstract long getStaticDefaultWaitTime();
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/com/openshift/jenkins/plugins/pipeline/dsl/OpenShiftImageStreams.java:
--------------------------------------------------------------------------------
1 | package com.openshift.jenkins.plugins.pipeline.dsl;
2 |
3 | import com.openshift.jenkins.plugins.pipeline.Auth;
4 | import com.openshift.jenkins.plugins.pipeline.ParamVerify;
5 | import com.openshift.jenkins.plugins.pipeline.model.IOpenShiftPluginDescriptor;
6 | import hudson.Extension;
7 | import hudson.scm.SCM;
8 | import hudson.util.FormValidation;
9 | import org.jenkinsci.plugins.workflow.steps.scm.SCMStep;
10 | import org.kohsuke.stapler.DataBoundConstructor;
11 | import org.kohsuke.stapler.DataBoundSetter;
12 | import org.kohsuke.stapler.QueryParameter;
13 |
14 | import javax.annotation.Nonnull;
15 | import javax.servlet.ServletException;
16 | import java.io.IOException;
17 |
18 | /**
19 | * SCMStep for OpenShiftImageStreams
20 | */
21 | public class OpenShiftImageStreams extends SCMStep {
22 |
23 | protected String name;
24 | protected String tag;
25 | protected String apiURL;
26 | protected String namespace;
27 | protected String authToken;
28 | protected String verbose;
29 |
30 | // marked transient so don't serialize; constructed on per request basis
31 | protected transient Auth auth;
32 |
33 | @DataBoundSetter
34 | public void setName(String name) {
35 | this.name = name != null ? name.trim() : null;
36 | }
37 |
38 | @DataBoundSetter
39 | public void setTag(String tag) {
40 | this.tag = tag != null ? tag.trim() : null;
41 | }
42 |
43 | @DataBoundSetter
44 | public void setApiURL(String apiURL) {
45 | this.apiURL = apiURL != null ? apiURL.trim() : null;
46 | }
47 |
48 | @DataBoundSetter
49 | public void setNamespace(String namespace) {
50 | this.namespace = namespace != null ? namespace.trim() : null;
51 | }
52 |
53 | @DataBoundSetter
54 | public void setAuthToken(String authToken) {
55 | this.authToken = authToken != null ? authToken.trim() : null;
56 | }
57 |
58 | @DataBoundSetter
59 | public void setVerbose(String verbose) {
60 | this.verbose = verbose != null ? verbose.trim() : null;
61 | }
62 |
63 | public void setAuth(Auth auth) {
64 | this.auth = auth;
65 | }
66 |
67 | public String getName() {
68 | return name;
69 | }
70 |
71 | public String getTag() {
72 | return tag;
73 | }
74 |
75 | public String getApiURL() {
76 | return apiURL;
77 | }
78 |
79 | public String getNamespace() {
80 | return namespace;
81 | }
82 |
83 | public String getAuthToken() {
84 | return authToken;
85 | }
86 |
87 | public String getVerbose() {
88 | return verbose;
89 | }
90 |
91 | public Auth getAuth() {
92 | return auth;
93 | }
94 |
95 | @DataBoundConstructor
96 | public OpenShiftImageStreams(String name, String tag, String namespace) {
97 | this.name = name != null ? name.trim() : null;
98 | this.tag = tag != null ? tag.trim() : null;
99 | this.namespace = namespace != null ? namespace.trim() : null;
100 | }
101 |
102 | @Nonnull
103 | @Override
104 | protected SCM createSCM() {
105 | com.openshift.jenkins.plugins.pipeline.OpenShiftImageStreams scm = new com.openshift.jenkins.plugins.pipeline.OpenShiftImageStreams(
106 | name, tag, apiURL, namespace, authToken, verbose);
107 | scm.setAuth(auth);
108 | return scm;
109 | }
110 |
111 | @Extension(optional = true)
112 | public static final class DescriptorImpl extends SCMStepDescriptor
113 | implements IOpenShiftPluginDescriptor {
114 |
115 | public DescriptorImpl() {
116 | // Fail now if dependency plugin not loaded. Descriptor. will
117 | // actually fail anyway, but this is just to be sure.
118 | com.openshift.jenkins.plugins.pipeline.OpenShiftImageStreams.class
119 | .hashCode();
120 | }
121 |
122 | @Override
123 | public String getFunctionName() {
124 | return "openshiftImageStream";
125 | }
126 |
127 | @Override
128 | public String getDisplayName() {
129 | return "OpenShift ImageStreams";
130 | }
131 |
132 | public FormValidation doCheckTag(@QueryParameter String value)
133 | throws IOException, ServletException {
134 | return ParamVerify.doCheckTag(value);
135 | }
136 |
137 | public FormValidation doCheckName(@QueryParameter String value)
138 | throws IOException, ServletException {
139 | return ParamVerify.doCheckImageStreamName(value);
140 | }
141 | }
142 | }
143 |
--------------------------------------------------------------------------------