How to get the Build Number of another plan?

nikoWah
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!
September 5, 2018

Hi

Is there a way to get the build number of another plan? 

Would be best if I could just reference it as a bamboo variable in my current plan, not with an REST API call, just like TEAMCITY.

https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html

Thanks.

1 answer

1 accepted

0 votes
Answer accepted
Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 13, 2018

Hello Niko,

I have the impression that it can only be achieved in TeamCity when using a snapshot dependency (Using the Build Number of another Configuration – TeamCity Support).

I'm not sure if this is the same idea (I don't work with TeamCity), but in Bamboo we have the plan build dependencies (Setting up plan build dependencies - Atlassian Documentation) to set relationship between plans. Although we have that, variables cannot be passed from parent plans to child plans. We have a feature request to improve that ([BAM-3175] In order to have pass control to child build plans, Bamboo should have an option of passing variables between parent and child builds), but there is a workaround you can use.

If your plans have a dependency relationship you can do this:

  1. Create a variables file through a script task in your parent plan to export the variables you want in the child plan, e.g.
    echo "planKey="${bamboo.planKey} >> variables
    echo "buildNumber="${bamboo.buildNumber} >> variables
  2. Create an artifact definition to publish this file
  3. Download the artifact in the child plan
  4. Add an inject variables task to load the variables in the child plan

The process above can be used to get any variables from the parent plan and publish them in the child plan.


You can also:

  • Get the latest build number from the DB:
    SELECT MAX(BUILD_NUMBER) FROM BUILDRESULTSUMMARY WHERE BUILD_KEY='<PLAN-KEY>'
  • Or even (not desired for you) REST API:
    <Bamboo_URL>/rest/api/latest/result/<PROJ-KEY>-latest

    Linux example:

    curl -u <USER>:<PASSWORD> -X GET '<Bamboo_URL>/rest/api/latest/result/<PROJ-KEY>-latest' | awk -v FS="(resultNumber)" '{print $2}' | tr -d '<>/'

I hope it helps. 

nikoWah
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!
September 13, 2018

Hi Daniel

Thanks for the reply. We actually implemented the solution you mentioned, exposing the build number as an artefact.

Glad to know that there is a feature request opened as this is a very useful function to have.

I have written a guide for others who might be interested.

https://medium.com/@niko.wah.hn/how-to-share-build-number-between-plans-in-bamboo-ci-f708d55483f1

Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 14, 2018

Hi Niko,

I'm glad to know you already implemented it and thank you so much for writing the article and sharing it here =]


Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events