Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Time to cleanup unknown and incomplete build results

Hi awesome community, 

 

Time to time we do many reports, also, our Bamboo instance grows so faster. 

But we need to provide a high-performance service and make reports based exist build results because DevOps metrics are core for the release management.

So let's investigate how we can do a cleanup and reduce our spaghetti code for the report collecting purpose.

 

1. Let's check what kind of status do we have?

image.png

  • Successful,
  • Failed,
  • Unknown ( means Currently running),
  • Unknown - something wrong,
  • Incomplete.

2. I mean the grey one result, if you click you will like this info

image.png

It's incomplete status. 

About the unknown result, no worry it will not be removed if it's currently running a job.

You can test and further investigate using that article:

 

3. How we can remove build result ? 

Use that path for remove build result.  

/build/admin/deletePlanResults.action

You can check a full method here.

 

4. So let's automate ? 

That automation based on small simple wrapper of REST API for the Atlassian products.

from atlassian import Bamboo
from var import config
import logging

"""
That example shows how to clean up Bamboo incomplete or Unknown build results
"""

logging.basicConfig(level=logging.ERROR)

REMOVE = True
STATUS_CLEANED_RESULTS = ['Incomplete', 'Unknown']
EXCLUDED_PROJECTS = ["EXCLUDE_PROJECT"]
BAMBOO_LOGIN = config.JIRA_LOGIN
BAMBOO_PASS = config.JIRA_PASSWORD
BAMBOO_URL = config.BAMBOO_URL


def get_all_projects():
return [x['key'] for x in bamboo.projects(max_results=1000)]


def get_plans_from_project(proj):
return [x['key'] for x in bamboo.project_plans(proj)]


def get_branches_from_plan(plan_key):
return [x['id'] for x in bamboo.search_branches(plan_key, max_results=1000, start=0)]


def get_results_from_branch(plan_key):
return [x for x in bamboo.results(plan_key, expand='results.result', max_results=100, include_all_states=True)]


def remove_build_result(build_key, status):
result = bamboo.build_result(build_key=build_key)
if result.get("buildState") == status:
print("Removing build result - {}".format(build_key))
if REMOVE:
bamboo.delete_build_result(build_key=build_key)


def project_review(plans):
for plan in plans:
print("Inspecting {} plan".format(plan))
branches = get_branches_from_plan(plan)
for branch in branches:
build_results = get_results_from_branch(branch)
for build in build_results:
build_key = build.get('buildResultKey') or None
print("Inspecting build - {}".format(build_key))
if build_key:
for status in STATUS_CLEANED_RESULTS:
remove_build_result(build_key=build_key, status=status)


if __name__ == '__main__':
bamboo = Bamboo(
url=BAMBOO_URL,
username=BAMBOO_LOGIN,
password=BAMBOO_PASS,
timeout=180)
projects = get_all_projects()
for project in projects:
if project in EXCLUDED_PROJECTS:
continue
print("Inspecting project - {}".format(project))
results = []
all_plans_of_project = get_plans_from_project(project)
project_review(plans=all_plans_of_project)

 

That's all. 

 

I hope it was helpful for you. As result for me 900+ plans - was cleaned and service start to work faster as before, and removed more if-else condition in the scripts.

 

Cheers,

Gonchik Tsymzhitov

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events