Hi Team,
We are planning to trigger a azure release pipeline to passing the variables from jira user request, Can we do it using script runner?
You can trigger anything that has some web API with Scriptrunner.
But I'm not familiar with azure pipeline releases. There is probably a similar community forum for that project where you can ask how the APIs work.
But from the Scriptrunner's point of view, you will have to identify what you want your jira trigger will be. It could be a workflow, a scheduled job, a listener, or some user action through the UI.
Then, you'll need to consider what type of data the azure API might need and if it's already available within your Jira context or if you need to ask the user to provide additional information somehow.
Then, you can use the appropriate Scriptrunner configuration to gather the data and make an API call. Depending on the API, the data will have to be formatted a certain way. Probably "json" string. But some older APIs prefer xml.
Then, there are multiple libraries with which you can make the api call.
My favorite is HttpBuilder, a sample call would look like this:
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
def apiUrl = "https://somesitewithapi.com"
def httpBuilder = new HTTPBuilder(apiUrl)
def payload = [some:'payload structured data']
def responseJson //this will hold the data returned by the api
httpBuilder.request(Method.POST, ContentType.JSON) {
headers."Authorization" = "some token as required by the api"
uri.path = "/path/to/api/endpoint"
body = payload //this will be converted to json automatically
response.success = { response, json ->
if (json) {
responseJson = json
}
}
response.failure = { resp, data ->
log.error "httprequest failed: $data"
}
}
log.info "Data received from $apiUrl: $responseJson"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.