Get all members of Jira _not_ in a particular group

Paul Nichols January 9, 2014

My overarching task is to get all members of Jira _except those_ in a particular group, but I think I need some intermediary help before I can get there. I'm using jira-python, and I've gotten so far as to sort of get the group I need:

print jira.groups(query='jira-developers')

gives me

{u'header': u'Showing 1 of 1 matching groups', u'total': 1, u'groups': [{u'html': u'<b>jira-developers</b>', u'name': u'jira-developers'}]}

which was not the format I expected, but fine. I can't get the members of that group. The documentation seems to suggest that jira.group_members(group) should work, but I get the error that jira has no attribute group_members. Either the docs are lying or I'm an idiot, which are at least equally likely.

4 answers

1 accepted

0 votes
Answer accepted
rverschoor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 10, 2014

This works fine for me:

from jira.client import JIRA

options = {'server': 'http://localhost:8080'}
basic_auth = ('admin', 'password')
jira = JIRA(options, basic_auth)

users = jira.group_members('jira-developers')
print users

N.B. You must be authenticated and have permission to run these queries.
If you're not the output of this script will give you a clue:

  • HTTP 401 "Client must be authenticated to access this resource".
    This means you're not logged in.
    Supply your credentials in 'basic_auth'.
  • HTTP 403 "You are not authorised to perform this action. Administrator privileges are required."
    The user account you used to login doesn't have the 'Browse User' permission.

Your original quest to get all user which are not in a particular group will require some scripting.
I assume all your users are in the group 'jira-users'.

  • Retrieve the members of 'jira-users' and store them in a list.
  • Retrieve the members of the group you want to exclude.
  • Delete all members of the excluded group from the jira-users list.
  • The remaining users in the list are users which are not a member of the particular group.
Paul Nichols January 12, 2014

I'm still getting `AttributeError: 'JIRA' object has no attribute 'group_members'` from your code (obviously with my server, username and password substituted)

Paul Nichols January 12, 2014

No, it's called something else. I created the script within sublime and I'm running it from there. Does that matter?

rverschoor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 12, 2014

Wild guess: did you call your script "jira.py"?
If so, rename it to something else, delete the "jira.pyc" file, and try again.

Edit: scratch that, you would get another error.

Sorry, I don't know.
It could be a problem with your jira_python installation, but that's just a guess.

rverschoor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 12, 2014

It shouldn't, but that's easy enough to try out by running the script from the commandline.

Paul Nichols January 12, 2014

No help. Also tried typing in the same commands directly in the python prompt. Same error message: AttributeError: 'JIRA' object has no attribute 'group_members'

rverschoor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 13, 2014

I have no clue.

Can you try installing Python and jira_python in a clean environment (VM or another PC) to see if that works?
If that works it proves your own installation has some problems.

0 votes
rverschoor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 17, 2014

I retried, installing jira-python from scratch in a virtualenv, and everything just works out of the box.
It looks like your problem is related to your environment, but I have no clue what it could be :(

0 votes
rverschoor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 13, 2014

I'm not a regular user of jira-python, so I don't know. Have just installed and tested it for this problem.

0 votes
Paul Nichols January 13, 2014

It's already in a virtual environment. What was the command for getting group_members pre-6?

rverschoor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 13, 2014

I'm not a regular user of jira-python, so I don't know. Have just installed and tested it for this problem.

Suggest an answer

Log in or Sign up to answer