/
Invoking a Web Service
Invoking a Web Service
Following example show how you can trigger a build on build server when a component version or bundle is released. Of course exact URL and body of request will change depending on which build server you are using. But it should be a good starting point for you.
Following code assumes that you are listening both BundleReleasedEvent and ComponentVersionReleasedEvent. If you are listening only one of them, you can adjust the event type check (instanced) accordingly.
import com.deniz.jira.versioning.componentversions.events.*;
import com.deniz.jira.versioning.bundles.events.*;
import com.deniz.jira.versioning.bundles.*;
import com.deniz.jira.versioning.*;
import com.atlassian.jira.component.*;
//We need to load Conf. Man. classes differently using getOSGiComponentInstanceOfType
def bundleService = ComponentAccessor.getOSGiComponentInstanceOfType(BundleService.class);
def triggerBuildComponentAndVersionPair(long componentId, long versionId) {
log.debug("Triggering build for component:{} and version:{}", componentId, versionId);
def post = new URL("https://httpbin.org/post").openConnection();
def message = """{\"componentId\":\"${componentId}\", \"versionId\": \"${versionId}\"""";
post.setRequestMethod("POST")
post.setDoOutput(true)
post.setRequestProperty("Content-Type", "application/json")
post.getOutputStream().write(message.getBytes("UTF-8"));
def postRC = post.getResponseCode();
log.debug("==>" + postRC.toString());
if(postRC.equals(200)) {
log.debug(post.getInputStream().getText());
} else {
log.error("Request failed");
}
}
def event = parameters.event;
//since we are listening for both events we need to handle them differently
if (event instanceof ComponentVersionReleasedEvent) {
def componentVersion = event.componentVersion;
triggerBuildComponentAndVersionPair(componentVersion.componentId, componentVersion.versionId);
} else if (event instanceof BundleReleasedEvent) {
def componentsOfBundle = bundleService.getComponentsOfBundle(event.bundle.getID());
componentsOfBundle.each{content -> triggerBuildComponentAndVersionPair(content.componentId, content.versionId)}
}
, multiple selections available,
Related content
Cloning a Bundle to Another Project
Cloning a Bundle to Another Project
Read with this
Scripting
Scripting
Read with this
Hello World Script
Hello World Script
Read with this
Component Attributes
Component Attributes
Read with this