Im currently working on ad-hoc integration of JIRA to other business using REST API. There is no problem create or modify tasks but I unable to adding attachment (xlsx file).
JIRA documentation is pretty good https://docs.atlassian.com/jira/REST/latest/#d2e2035 and curl example works pretty well for me.
Actually now I use curl command executed in ExecuteScript component.
function integer transform() {
string script = 'curl -D- -k'
+ ' -u ${JIRA_AUTH}' // HTTP Basic auth. credentials, format: USER:PASSWORD - admin:admin
+ ' -X POST' // HTTP POST method
+ ' -H "X-Atlassian-Token: nocheck"' // XSRF protection handling
+ ' -F "file=@' + toAbsolutePath(dictionary.FILE_TO_ATTACH_URL) + '"' // file to submit
+ ' ${JIRA_INSTANCE_REST_API_URL}/issue/' + $in.0.key + '/attachments'; // JIRA instance REST API URL - http://localhost:2990/jira/rest/api/2/issue/TEST-1/attachments
$out.0.script = script;
return ALL;
}
As You can see - This solution has security issue because of password revealing in temporary script on filesystem. This solution is only acceptable as short-term workaround. HTTP Basic auth is a must.
I need to use HTTPConnector to this. Sadly Multipart entities are not described good enough. Doc examples and reality differs.
Use file as multipart entity doc example:
To use files as multipart entitie map only *_File field. Do not map _Content field.
$out.3.field3_File = "${PROJECT}/workspace.prm";
In reality, multipart fields are mapped as $out.4.* (not $out.3.*) and there is no such field $out.4.fieldX_File but fieldX_EntitySourceFile. I found it pretty misleading.
I found this HTTPConnector mapping to run with no error or invalid response code on my private JIRA mock, but attachment has not been added.
function integer transform() {
map[string,string] headers;
headers["Authorization"] = "Basic " + byte2base64(str2byte("admin:admin","utf-8"));
headers["X-Atlassian-Token"] = "nocheck";
$out.0.additionalHTTPHeaders = headers;
$out.0.URL = "http://localhost:2990/jira/rest/api/2/issue/TEST-1/attachments";
// multipart attachment
$out.4.field1_EntitySourceFile = "d:\\xxx.txt";
return ALL;
}
Other properties as defauls except “Multipart entities” set to “field1”. There is warning
‘Multipart entities’ attribute will be ignored, because ‘Add input fields as parameters’ attribute is set to ‘false’.
It leads me to switch-on and -off that parameter with no effect.
Please help me to set parametters properly to do the task.
Thank You
Martin
Environment used:
Local DEV CloverETL installation: CloverETL Server 4.0.4.13/13 (Tomcat bundle) + Designer 4.0.4.013
Local DEV JIRA installation: latest JIRA Plugin SDK (atlas-run-standalone --product jira)