Send a HTTP POST as a post function.

Hi All,

I am trying to figure out which plugin (if any) can help me solve this business case.

When we transition through a workflow, we would like to have JIRA send a HTTP POST to a different piece of software that triggers some events in our organization. If this remote software returns an error or is non-responsive, the issue should go into a "Needs Attention" state with some field populated by the error. If the POST succedes, the issue will transition to the next step properly.

I do not have the expertise on hand to develop a full-blown plugin. I do see there are two plugins that may help us, Script Runner and JIRA Scripting Suite. Does anyone know if either of those will work for our use case?

Thank you!

1 answer

1 accepted

1 vote
Accepted answer

There might be ready plugins to post data but i'm not aware of any right now. It can be surely done using the script runner plugin. You will need two post functions provided by this plugin:

1. "Groovy post function" to post data to your backend and set a custom field, e.g. "error" to the error message returned in the http response

2. As the last post function you need a "Fast-track transition issue" post function to transition to your error state when the custom field "error" is set, i.e. when an error has occured

I have no ready code right now but posting to a website using basic authentication is straightfoward and you can find many examples.

Ok, meanwhile i have got some code for 1) but it is not tested.

import org.apache.commons.httpclient.Credentials
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials
import org.apache.commons.httpclient.auth.AuthScope
import org.apache.commons.httpclient.methods.PostMethod;

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField

// where to post

// user/password used for access

// if parameters are needed

// custom field containing error

HttpClient client = new HttpClient();
Credentials credentials = new UsernamePasswordCredentials(USER,PASSWORD);
client.getParams().setParameter("http.useragent", "GroovyScripClient");
client.getState().setCredentials(AuthScope.ANY, credentials);

PostMethod method = new PostMethod();
method.addParameter(EXAMPLE1_KEY, EXAMPLE1_VAL);

String error = null
	int returnCode = client.executeMethod(method);
	if (returnCode != HttpStatus.SC_OK) {
		error = method.getResponseBodyAsString();
	} else { // just consume output
} catch (Exception e) {
	error = e.getMessage();
} finally {

CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
CustomField cfError = customFieldManager.getCustomFieldObjectByName(CFNAME);
if (cfError != null) {
	issue.setCustomFieldValue(cfError, error)

That's great Dieter! I will try and implement something based on your recommendation and example next week.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,519 views 15 21
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