Skip to content

Instantly share code, notes, and snippets.

@garethahealy
Created February 14, 2018 18:06
Show Gist options
  • Save garethahealy/29001bf664944dfba8098dd625f9e90d to your computer and use it in GitHub Desktop.
Save garethahealy/29001bf664944dfba8098dd625f9e90d to your computer and use it in GitHub Desktop.
Add to openshift client plugin config
import jenkins.model.Jenkins
import com.openshift.jenkins.plugins.OpenShift
import net.sf.json.JSONObject
import net.sf.json.JSONArray
import org.kohsuke.stapler.Stapler
import org.kohsuke.stapler.RequestImpl
import javax.servlet.http.HttpServletRequest
def httpServletRequest = [
getRequestURI: { null }
] as javax.servlet.http.HttpServletRequest
def servletConfig = [
getServletContext: { Jenkins.getInstance().servletContext },
getInitParameter: { null },
getServletName: { "" }
] as javax.servlet.ServletConfig
Stapler stapler = new Stapler()
stapler.init(servletConfig)
RequestImpl requestImpl = new RequestImpl(stapler, httpServletRequest, [] as java.util.List<org.kohsuke.stapler.AncestorImpl>, null)
JSONObject cluster1 = new JSONObject();
cluster1.put("name", "cluster1")
cluster1.put("serverUrl", "https://cluster:8443")
cluster1.put("serverCertificateAuthority", "cat from file")
JSONArray clusterConfigs = new JSONArray()
clusterConfigs.add(cluster1)
JSONObject openshift = new JSONObject()
openshift.put("clusterConfigs", clusterConfigs)
JSONObject json = new JSONObject()
json.put("openshift", openshift)
def openshiftDSL = Jenkins.getInstance().getDescriptor("com.openshift.jenkins.plugins.OpenShift")
openshiftDSL.configure(requestImpl, json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment