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

How to get Bamboo environment results from REST API

These are the steps you can use to get the environment results of a deployment. You just need to know the plan-key associated with that deployment.
Ok, you will also need Curl, jq (command-line JSON processor) on a Unix like terminal.

  1. Get the <PLAN_KEY> and run the following request:
     curl -u <USER>:<PASSWORD> \
    -X GET -p <BAMBOO_URL>/rest/api/latest/deploy/project/forPlan?planKey=<PLAN-KEY> \
    | jq -r '.[] | "Name: " + .name + "\tdeploymentId: " + (.id|tostring)'
    It should give you a result like:
     Name: <DEPLOYMENT_NAME>       deploymentId: <DEPLOYMENT_ID>
  2. Get the <DEPLOYMENT_ID> and run:
    curl -u <USER>:<PASSWORD> \
    -X GET -p '<BAMBOO_URL>/rest/api/latest/deploy/project/<DEPLOYMENT_ID>' \
    | jq -r '.environments[] | "Name: " + .name + "\tenvironmentId: " + (.id|tostring)'
     As a result, you should get:
     Name: <ENVIRONMENT_NAME>      environmentId: <ENVIRONMENT_ID>
  3. Following the same idea, get the <ENVIRONMENT_ID> and run:
    curl -u <USER>:<PASSWORD> \
    -X GET -p '<BAMBOO_URL>/rest/api/latest/deploy/environment/<ENVIRONMENT_ID>/results' \
    | jq -r '.results[] | "\nCreator: " + .deploymentVersion.creatorDisplayName + "\nBranch: " + .deploymentVersion.planBranchName + "\nDeployment State: " + .deploymentState + "\nLife Cycle State: "+ .lifeCycleState'

    With the last request, you can get whatever information is available in the main rest, by adjusting the jq query set throught the pipe. In this example, it was configured to provide the creator, branch, and statuses of the given environment.
    Creator: <USER>
    Branch: <BRANCH>
    Deployment State: <DEPLOYMENT_STATE>
    Life Cycle State: <LIFE_CYCLE_STATE>

    e.g.

    Creator: admin
    Branch: master
    Deployment State: SUCCESS
    Life Cycle State: FINISHED

 

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events