The problem is due to the deprecation of UrlConnection class.
You should update the code to use the HttpURLConnection class instead. It could be something like this:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import groovy.json.StreamingJsonBuilder;
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import java.net.HttpURLConnection
@BaseScript CustomEndpointDelegate delegate
triggerJenkinsBuild(httpMethod: "GET") { MultivaluedMap queryParams ->
def issueId = queryParams.getFirst("issueId") as String // use the issueId to retrieve this issue
def flag = [
type : 'success',
title: "Build scheduled",
close: 'auto',
body : "A new build has been scheduled related with "+issueId
]
URL url;
def jobName = "java-junit-calc" // could come from a CF in the Test Plan
def jenkinsHostPort = "192.168.56.102:8081" // could be defined elsewhere
def token = "iFBDOBhNhaxL4T9ass93HRXun2JF161Z" // could also come from a CF in the Test Plan
def username = "admin" // probably, would need to be stored elsewhere
def password = "fa02840152aa2e4da3d8db933ec708d6" // probably, would need to be stored elsewhere
def baseURL = "http://${jenkinsHostPort}/job/${jobName}/buildWithParameters?token=${token}&TESTPLAN=$issueId"
url = new URL(baseURL);
def body_req = []
def authString = "${username}:${password}".bytes.encodeBase64().toString()
HttpURLConnection connection = (HttpURLConnection) url.openConnection()
connection.setRequestMethod("POST")
connection.setDoOutput(true)
connection.addRequestProperty("Authorization", "Basic ${authString}")
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }
connection.connect();
log.debug(connection.getResponseCode())
log.debug(connection.getResponseMessage())
if (connection.getResponseCode() == 201) {
Response.ok(JsonOutput.toJson(flag)).build()
} else {
//Response.status(Response.Status.NOT_FOUND).entity("Problem scheduling job!").build();
}
}