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

How to list plan build status using REST API

A recent community question was inquiring for a report to list all Bamboo build plan branch statuses. Bamboo does not have such a report but it could be built using some REST APIs.

This article is intended to show a path that could be used to get this information using a UNIX Like system terminal and ./jq command-line JSON processor.

The following REST calls were then used for this:

  • /rest/api/latest/project
    Get the list of projects
  • /rest/api/latest/project/$PROJECT?expand=plans
    Get the plans from a given project
  • /rest/api/latest/plan/$PLAN/branch
    Get the plan branches from a given plan
  • /rest/api/latest/result/$PLAN_BRANCH
    Get the plan branches status

Reference: Bamboo REST API documentation 6.9.2.

The result was the following script tested with bash:

#!/bin/bash

USER=<USER>
PASSWORD=<PASSWD>
BAMBOO_URL=<BAMBOO_URL>

PROJECTS=`curl -s -u $USER:$PASSWORD \
-H 'Accept: application/json' \
-X GET "$BAMBOO_URL/rest/api/latest/project" \
| jq -r '.projects.project[] | .key'`

PLANS=""
for PROJECT in $PROJECTS
do
    PROJECT_PLANS=`curl -s -u $USER:$PASSWORD \
    -H 'Accept: application/json' \
    -X GET "$BAMBOO_URL/rest/api/latest/project/$PROJECT?expand=plans" \
    | jq -r '.plans.plan[] | .key'`
    PLANS+=" $PROJECT_PLANS"
done

PLANS_AND_BRANCHES=""
for PLAN in $PLANS
do
    PLANS_AND_BRANCHES+=" $PLAN"
    BRANCHES=`curl -s -u $USER:$PASSWORD \
    -H 'Accept: application/json' \
    -X GET "$BAMBOO_URL/rest/api/latest/plan/$PLAN/branch" \
    | jq -r '.branches.branch[] | .key'`
    PLANS_AND_BRANCHES+=" $BRANCHES"
done

for PLAN_BRANCH in $PLANS_AND_BRANCHES
do 
    curl -s -u $USER:$PASSWORD \
    -H 'Accept: application/json' \
    -X GET "$BAMBOO_URL/rest/api/latest/result/$PLAN_BRANCH" \
    | jq -r '.results.result[0] | "Plan:" + .key + " Name:\"" + .plan.name + "\" lifeCycleState:" + .lifeCycleState + " buildState:" + .buildState'
done

⚠️ Please make sure you edit the <USER>, <PASSWORD> and <BAMBOO_URL> before using this script. You can also add arguments to remove this information from the script. I'll leave that for you.

I hope that helps.

 

 

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events