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

Bamboo Deployment Version ID from REST API

talleym August 7, 2019

Given a build result key (e.g., BAM-BOO-23), how do I find the associated release created in a deployment plan? I need a way to find this information through the REST API.

 

Here's the trouble I'm having:

*I can't find associated release information anywhere in the build result's REST resources.

*Deployment plan REST resources only contain the associated build result if that build result produced an artifact. Not all of my plans produce artifacts, and I can't start making them produce artifacts just for the sake of keeping build information.

1 answer

0 votes
Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 13, 2019

Hello @talleym

I have an approach that could solve this issue. It is not an elegant solution (a direct rest), but at least It will give you what you need.

  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[] | "Version: " + .deploymentVersionName + "\treasonSummary: " + .reasonSummary'

    This one should give you the deploymentResultId you need:
     Version: <VERSION> reasonSummary: Child of <a href="<BAMBOO_URL>/browse/<BUILD-RESULT-KEY>"><BUILD-RESULT-KEY></a>

    ⚠️Please notice that the above requests use jq (command-line JSON processor) to simplify filtering the results.

The last one will give you the information you need even if there is no artifact associated to that build.

I hope that helps.

talleym August 13, 2019

I appreciate the help! The problem here is that not all of our releases are automatic; in the event that someone started the release themselves, the reasonSummary becomes "Manual run by ...", as opposed to the plan name.

Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 13, 2019

You are correct. And considering what you shared, the only option I see now is the direct access to DB:

SELECT 
   CONCAT(dvp.plan_key, CONCAT('-',dvp.build_number)) build,
   dv.plan_branch_name,
   dv.name
FROM
   deployment_version dv
   LEFT JOIN dep_version_planresultkeys dvp
   ON dv.deployment_version_id = dvp.deployment_version_id

I also created a feature request for this:

I hope that helps you to move forward.

talleym August 13, 2019

Thank you for creating a feature request. The servers that need to run this script do not have access to the DB.

Like Daniel Santos likes this
Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 13, 2019

I'm afraid I don't have more options for you.
I wish I could give you more tips.

Jack Dillon
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 29, 2021

Hi @Daniel Santos apologies for reviving an old post. I am currently playing around with the Bamboo rest api and am trying to get the deployed version to an environment. Currently below works for me:

http://localhost:8085/rest/api/latest/deploy/environment/{environment_id}/results

 

however it seems I need to be authenticated even though my deployment environment allows anonymous users to view (I can view this info even when logged out through the ui)

I am thinking possibly this endpoint also returns details that requires you to be logged in.

is there another endpoint I can call to give me deploymentVersionName without auth?

 

Other details like:

"deploymentState": "SUCCESS",
"lifeCycleState": "FINISHED",
"startedDate": 1611924003709,
"queuedDate": 1611924003727,
"executedDate": 1611924003747,
"finishedDate": 1611924004523,

 

would be nice as well, but no biggie if not possible without auth for these ones.

Jack Dillon
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 30, 2021

All good, ended up just generating a personal access token with read only permission and it worked.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events