Skip to content

Instantly share code, notes, and snippets.

@nishantagarwal1990
Created September 20, 2017 22:39
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 nishantagarwal1990/8be1f02f6d68edcfcccd59bbc40189b0 to your computer and use it in GitHub Desktop.
Save nishantagarwal1990/8be1f02f6d68edcfcccd59bbc40189b0 to your computer and use it in GitHub Desktop.
Setting access key for Metrics Plugin
import org.kohsuke.stapler.*
import jenkins.metrics.api.*
import net.sf.json.JSONObject
def metrics = jenkins.model.Jenkins.instance.getExtensionList(jenkins.metrics.api.MetricsAccessKey.DescriptorImpl)[0]
def req = Stapler.getCurrentRequest();
JSONObject obj = new JSONObject();
JSONObject child_obj = new JSONObject();
child_obj.put("key", "33DD8B2F1FD645B814993275703F_EE1FD4D4E204446D5F3200E0F6-C55AC14E");
child_obj.put("canPing", "true");
child_obj.put("canHealthCheck", "true");
child_obj.put("canMetrics", "true");
child_obj.put("origins", "*");
obj.put("accessKeys", child_obj);
metrics.configure(req, obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment