Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

Assing to field for Jira pluging


#1

Hi!

We are now, trying the TestRail, and try to integrate it with Jira.
I’m already done with user mapping and versioning, thank’s for you docs.
But i still need the assign to field.

I could not find any examples of how to implement the “assing to” into the Jira plug-in.

On stackoverflow i found this code, and it looks like works fine:

[code]<?php
$base_url = ‘http://jiraserver/’;
$wsdl = $base_url . ‘rpc/soap/jirasoapservice-v2?wsdl’;

$username = ‘testrail’;
$password = ‘testrail’;

$client = new SoapClient($wsdl);

try {
$token = $client->login($username, $password);
}
catch (SoapFault $fault) {
echo “Error logging in to JIRA”;
print_r($fault);
}

$code = ‘JIRAETC’;

$project = $client->getProjectByKey($token, $code);

$role = $client->getProjectRole($token, 10000); // 10000 is typically the “users” role

$users = $client->getProjectRoleActors($token, $role, $project);

print_r($users);

?>[/code]

But still I don’t realy understand how to implement it into the plug-in.

I’ve tried to make use it like it done with the “versions” but this chunk of code does not work:

[code]public function get_asignee($project_id)
{
$code = array($project_id);
$role_id = array(‘10000’);
$project = $this->_send_command(‘getProjectByKey’, $code);
$role = $this->_send_command(‘getProjectRole’, $role_id);
$data = array($role, $project);
$response = $this->_send_command(‘getProjectRoleActors’, $data);

if (!$response)
{
    return array();
}

$result = array();

foreach ($response as $asignee)
{
$as = obj::create();
$as->id = (string) $asignee->id;
$as->name = (string) $asignee->name;
$result[] = $as;
}

return $result;

}[/code]

I think that i’m doing smth wrong while parsing array.

Could you please help me to make it work?
Thanks in advance


#2

Hello,

Thanks for your request. I read that you need to have administrator permissions to request the list of JIRA users. Is the user that you use for the integration an administrator?

To debug the responses that you receive from JIRA you can enable debug logging and use TestRail’s internal log methods. This way you can look up the results from JIRA in TestRail’s log file:

http://docs.gurock.com/testrail-faq/system-script-debug

I hope this helps and I’m looking forward to your feedback.

Thanks,
Dennis


#3

Thanks for help.

Yes, I found out that requesting user should be project administrator.

I’ll try to debug the output. Using 1st script i mentioned i’ve got the output from jira, but it was not a simple array like it’s with the versions field.


#4

Sure, sounds good. Another approach you could use, if you don’t have too many users you need to assign bugs to, is to store the list of assignees in the defect plugin configuration (where you also store the connection details; e.g. an [assignees] section or similar).

Regards,
Dennis


#5

I’d make it work :slight_smile: by using getGroup() method of jira API, it’s much easier to parse.

I have another question regarding TestRails test-case fields.

Is it possible to get test-case title, precondition, steps to repro, and expected result, to the description field of defect tracking plugin?

I saw, $context is used in current realization. Does in have keys for precondition and steps fields?

We’d want to push the bug and it’s texts to jira so not to make developer navigate to testlink.


#6

Hello,

Great to hear that you got it working. If you don’t mind sharing the get_asignee method, that would be appreciated! :slight_smile:

Regarding your question: yes, you can access various context details via the $context variable and you can learn more about this here:

http://docs.gurock.com/testrail-integration/defects-plugins-custom#pushing_defects_without_a_dialog

The above list of attributes is not complete and you can also access things like $context[‘tests’][0]->case->custom_preconds (as this is actually a custom field) or ->title.

I hope this helps.

Thanks,
Dennis


#7

Here it is.

This function gets list of users, from jira user group(atlasian-users):

[code]public function get_asignee()
{

$data = array('atlassian-users');
$response = $this->_send_command('getGroup', $data);

 
if (!$response)
{
    return array();
}

$result = array();
$arruser = $response->users;


foreach ($arruser as $key=>$jirauser)
{
$as = obj::create();
$as->id = (string) $key;
$as->name = (string) $jirauser->fullname;
$result[] = $as;
}

return $result;

}
[/code]

And the second for setting asignee for push (i know it’s pretty awkward having to methods for one object, but i’m a total php noob):

[code]public function get_asignee_name($asignee_id)
{
$data = array(‘atlassian-users’);
$response = $this->_send_command(‘getGroup’, $data);

if (!$response)
{
    return array();
}


$arruser = $response->users;
$result = (string) $arruser[$asignee_id] -> name;

return $result;

}[/code]

Also asingee filed of creatIssue method requires string.

Also fetching the priority (we should also return string to jira):

[code]public function get_priority()
{

$response = $this->_send_command('getPriorities');

if (!$response)
{
    return array();
}

$result = array();
foreach ($response as $prior)
{
    $p = obj::create();
    $p->id = (string) $prior->id;
    $p->name = (string) $prior->name;
    $result[] = $p;
}

return $result;

}[/code]

Also i’d want to ask you for listing full $context object for me. As i was said I’m a totaly noob in php, and do not realy know how to view all the fields of $context.

Thank you in advance.


#8

Hello,

Thanks for sharing the code snippets, I’m sure this will be useful for other customers as well.

To take a look at all the available fields in the $context variable you can simply log it with the logger::debugr method:

http://docs.gurock.com/testrail-faq/system-script-debug

I hope this helps. Just let me know if you have further questions about this.

Regards,
Dennis


#9

listing $context works fine thank you.

There is another question (heh too many questioins i know).

I wanted to make jira-user-group configurable. You saw that now it’s hardcoded $data = array(‘atlassian-users’);

I’ve read this article http://docs.gurock.com/testrail-integration/defects-plugins-custom
And added jirausersgroup=jiragroup to configuration section of config.

Also parsed it in configure function: $this->_jirausersgroup = $ini[‘connection’][‘jirausersgroup’];

And finaly added to my method get_asignee() listed above:

$jirausersgroup =$this->_jirausersgroup; logger::debugr('jirausergroup-get', $jirausersgroup); $data = array($jirausersgroup);

But I get: Undefined property: Jira_api::$_jirausersgroup

Could you please explain using configuration. The article says: To access the defect tracker address in subsequent method calls, the plugin can thus simply access $this→_address.

But it does not work for me


#10

Hello,

Without seeing the whole code, I guess that the get_assignee function is in the _api class and the _jirausersgroup field is part of the plugin class, is this correct? Accessing _jirausersgroup only works from the plugin class (as this is the only class which has defined and configured this field). A simple solution would be to pass the group as parameter to get_assignee, for example:

[code]public function get_assignee($group)
{

$data = array($group);
$response = $this->_send_command('getGroup', $data);
..

[/code]

You can then just pass _jirausersgroup to the get_assignee function call.

I hope this helps,
Tobias


#11

Thanks a lot. I just didn’t realize that there several classes in plugin.