Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Help with getting all Projects listed when using the Atlassian Python Api

Adam Graham July 18, 2022

Hello all,

I am able to get information from a single project using the python api as seen in this code snippet: 

import os

from atlassian import Bamboo

BAMBOO_URL = os.environ.get("BAMBOO_URL", "http://bamboo.name.com/")
ATLASSIAN_USER = os.environ.get("ATLASSIAN_USER", "admin")
ATLASSIAN_PASSWORD = os.environ.get("ATLASSIAN_PASSWORD", "admin")

bamboo = Bamboo(url=BAMBOO_URL, username=ATLASSIAN_USER, password=ATLASSIAN_PASSWORD)
print(bamboo.project("projectName")) 

 but I can't get it to list all projects like this:

import os
from atlassian import Bamboo

BAMBOO_URL = os.environ.get("BAMBOO_URL", "http://bamboo.name.com/")
ATLASSIAN_USER = os.environ.get("ATLASSIAN_USER", "admin")
ATLASSIAN_PASSWORD = os.environ.get("ATLASSIAN_PASSWORD", "admin")

bamboo = Bamboo(url=BAMBOO_URL, username=ATLASSIAN_USER, password=ATLASSIAN_PASSWORD)

print(bamboo.projects(expand=None, favourite=False, clover_enabled=False, max_results=25))

any ideas on what I'm doing wrong?

1 answer

1 accepted

1 vote
Answer accepted
Florian Bonniec
Community Champion
July 18, 2022

Hi 

Do you have any error message ?

 

Seems to be the right function

https://github.com/atlassian-api/atlassian-python-api/blob/master/atlassian/bamboo.py

Adam Graham July 18, 2022

I don't get an error message, however all that is returned is 
<generator object Bamboo._get_generator at 0x000002988A054B30>

 

compared to the single result which gives me the desired result of:

{'expand': 'plans', 'key': 'myKey', 'name': 'Associated Name', 'link': {'href': 'http://bamboo.myurl.com/rest/api/latest/project/myKey', 'rel': 'self'}, 'plans': {'size': 38, 'start-index': 0, 'max-result': 25}}

Florian Bonniec
Community Champion
July 18, 2022

It seems that you have an answer but it return a Generator. I'm not familiar with it but you cannot use it like a list.

https://book.pythontips.com/en/latest/generators.html

You may try to copy the generator into a list

 

list(bamboo.projects(expand=None, favourite=False, clover_enabled=False, max_results=25))
Like # people like this
Adam Graham July 18, 2022

Thank you so much for helping. I didn't think to do that! Hopefully you have a great rest of your day.

Adam Graham July 18, 2022

@Florian Bonniec is there any way to store the items as a dictionary?

Florian Bonniec
Community Champion
July 18, 2022

I'm not familiar with python, but it seems to be possible.

https://stackoverflow.com/a/17815964

Like Adam Graham likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events