Implement a Groovy script as part of a transition

Hi ,

I wrote this Script below which send a REST POST to Bamboo, and it is working in the script runner console.

Now I want to implement it as part of a transition, and for that I need to get the current issue object ( I hope I'm using the correct terms )

Also if there is a better way to accomplish it, I would be happy know it :)


package com.onresolve.jira.groovy.canned.workflow.postfunctions

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.jira.groovy.canned.CannedScript;
import org.apache.commons.codec.binary.Base64;

def projectKey="**";
def buildKey="**";
def user = "****";
def passwd = "*****";
def requestMethod = "POST";
def URLParam = []

IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
//how to get current Subtask object

Issue parent = subTask.getParentObject();
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
CustomField accountNameObject = customFieldManager.getCustomFieldObjectByName("Account Name");

def accountName = parent.getCustomFieldValue(accountNameObject);

def parentIssueType = parent.issueTypeObject.name

def baseURL = "https://bamboo.*****.com:443/rest/api/latest/queue/${projectKey}-${buildKey}";
if (parentIssueType == "New DLM" || parentIssueType == "New Installer" ) {
    CustomField InstallerNameObject = customFieldManager.getCustomFieldObjectByName("Installer Name");
    def installerName = parent.getCustomFieldValue(InstallerNameObject);
    URLParam = ['bamboo.variable.accountName': accountName, 'bamboo.variable.installerName': installerName];
} else {
    CustomField OfferNameObject = customFieldManager.getCustomFieldObjectByName("Offer Name");
    def offerName = parent.getCustomFieldValue(OfferNameObject);
    CustomField OfferFlavorObject = customFieldManager.getCustomFieldObjectByName("OfferFlavor");
    def OfferFlavor = parent.getCustomFieldValue(OfferFlavorObject);
    URLParam = ['bamboo.variable.accountName': accountName, 'bamboo.variable.offerName': offerName, 'bamboo.variable.OfferFlavor': OfferFlavor];
}

def query = URLParam.collect { it }.join('&')

URL url;

url = new java.net.URL(baseURL + "?" + query);

def authString = user + ":" + passwd;
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
String authStringEnc = new String(authEncBytes);
URLConnection connection = url.openConnection();
connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
connection.setRequestMethod(requestMethod);
connection.setRequestProperty("Content-Type", "application/xml");
connection.setRequestProperty("Accept", "application/xml");

connection.connect();


println("status:" + connection.getResponseCode())
println("status:" + connection.getResponseMessage())
connection.getContent()

}

1 answer

1 accepted

This widget could not be displayed.
Henning Tietgens Community Champion Feb 26, 2014

In a scripted postfunction you can access issue which is the current issue object (as MutableIssue). It's binded to the script.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

528 views 3 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you