Created
April 14, 2017 11:54
-
-
Save cmaggiulli/ff42598171df59d56cd698e5eb5d38f6 to your computer and use it in GitHub Desktop.
New Relic deployment API for Jenkins build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grapes([ | |
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7') | |
]) | |
import groovyx.net.http.* | |
def API_KEY = "000000000000000000000000" | |
def APP_ID = "1111111" | |
def URL = "https://api.newrelic.com/v2/applications/${APP_ID}/deployments.json" | |
def http = new HTTPBuilder(URL) | |
http.setHeaders(["X-Api-Key":"${API_KEY}", "Content-Type":"application/json"]) | |
def json = '{"deployment": {"revision": "rev", "changelog": "Added", "description": "Added a deployments resource", "user": "me@example.com" }}' | |
http.request(Method.POST) { | |
requestContentType = ContentType.JSON | |
body = json | |
response.success = { resp, reader -> | |
println "${resp.statusLine}" | |
resp.headers.each { h -> | |
println " ${h.name} : ${h.value}" | |
} | |
// ret = reader.getText() ----- this needs to be parsed as JSON | |
// println ret | |
} | |
response.failure = { resp -> | |
println "${resp.statusLine}" | |
resp.headers.each { h -> | |
println " ${h.name} : ${h.value}" | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment