One of the options in Jira is to create a custom field. On transitioning a task to a certain state in my workflow I want to trigger a groovy script to send the data of this custom field via a REST Post request to an external php script.
I am using the following code:
import com.atlassian.jira.ComponentAccessor;
import groovyx.net.http.HTTPBuilder;
import static groovyx.net.http.ContentType.URLENC;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def email = customFieldManager.getCustomFieldObjectByName('Email Adress');
// this is the check
if(issue.getCustomFieldValue(email))
{
def http = new HTTPBuilder( 'http://www.example.com/Scripts/test.php' );
def postBody = [username: 'bob']; // will be url-encoded
http.post( path: '/', body: postBody, requestContentType: URLENC )
{
resp -> println "POST Success: ${resp.statusLine}";
assert resp.statusLine.statusCode == 201;
}
}
else
{
//do nothing
}
The debug/output/error console lists the following errors after running the code:
Script2.groovy: 1: unable to resolve class com.atlassian.jira.ComponentAccessor
@ line 1, column 1.
import com.atlassian.jira.ComponentAccessor;
^
Script2.groovy: 2: unable to resolve class groovyx.net.http.HTTPBuilder
@ line 2, column 1.
import groovyx.net.http.HTTPBuilder;
^
Script2.groovy: 3: unable to resolve class groovyx.net.http.ContentType
@ line 3, column 1.
import static groovyx.net.http.ContentType.URLENC;
^
3 errors
What is going wrong while importing the dependencies?