Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Is there an environment variable shared by all jobs of a given stage in Bamboo?



I'm using Bamboo environment variables to link various jobs together.

Given the following plan:

- Stage 1

  - Job 1-1

  - Job 1-2

- Stage 2

  - Job 2-1

  - Job 2-2


I can use `bamboo_planName` to get all the jobs for a given plan. This env var is available when the 4 `Job 1-1`, `Job 1-2`, `Job 2-1`, `Job 2-2` jobs execute.

I can also use `bamboo_buildPlanName`, to uniquely identify a given job across executions. I can use this to link together all executions of `Job 1-1` for instance.

Is there something similar for stages ? I'd like to be able to group via this mean all jobs for a given stage, say `Stage 1`. I would like to have an env var that is shared by `Job 1-1`, `Job 1-2` only, and *NOT* `Job 2-1`, `Job 2-2`.

Did I miss something ?

1 answer

Hi @François Guillot,

As far as I can tell we can't get that from variables.
I have a different suggestion for you. Get the plan key (it could be from a variable) and use a REST API:

curl -u admin:admin -H 'Accept: application/json' \
-X GET <BAMBOO-SERVER_URL>/rest/api/latest/search/jobs/<PLAN-KEY> \
| jq -r '.searchResults[]|" JobKey: " + .searchEntity.key + "\tStageName: " + .searchEntity.stageName'

⚠️Please notice that I used JQ -

 Expected outcome:

JobKey: MISC-STAG-JOB1   StageName: Default Stage
JobKey: MISC-STAG-JOB2   StageName: Default Stage
JobKey: MISC-STAG-JOB3   StageName: stage2
JobKey: MISC-STAG-JOB4   StageName: stage2

The will help you to know from which stage your JOBs are.
I hope that helps.

@Daniel Santos Great idea

I can make use of that

I tried to look at the REST API documentation, but couldn't find the '/rest/api/latest/search/jobs/' one ?

Is it not public yet ?

I would like to refine the query to get only a given job.

Basically I know the plan and the job, and I want the stage this jobs belongs too

Also, I tried


but it's a 'startsWIth' search, meaning that if several jobs starts with the 'jobName', I get several  results.

Could we get around that. Or find a way to pass the job key instead (which is unique) ? Passing the job key doesn't seem to work

Nonetheless, I think it would be great if Bamboo was providing something (like an env var) in future versions, as calling the API on each build brings a little overhead that could easily be avoided.

Hi @François Guillot

In my tests, it worked with the full name and the job key. I know the search mechanism is startWith which some times will bring multiple results, but that is less likely to happen due to the fact that we are searching inside the same plan (restricted set of results).

I've created this feature with the intention to simplify this scenario in future releases of Bamboo. Please vote and add yourself as a watcher to receive updates from our development team.

Hi @Daniel Santos 

Can you point me to the issue I should upvote ?


Regarding the job key, did you put in the 'searchTerm' query parameter of the REST api call ?

Hi @François Guillot

It was my bad, like an e-mail without attachments...
This is the feature request I've opened: 

Yes, I used the searchTerm to add the job key. When I tested I used only the last part of the job key. Something like:


Assuming the full job key was something like PROJ-PLAN-JOB2.

In my test, I have two jobs belonging to 2 stages of the same plan.

- one with


- one with


If I call the API with

searchTerm = TES

I get the 2 jobs above. OK, both starts with 'TES'.


But if I call it with


I get 0 results (weird, as the 2nd one starts with the same, isn't it ?)

I can't get what I'm doing wrong

I don't think you are doing anything wrong. 
The implementation is a startwith search as you already discovered.

The second format call with the full key is not covered by the search. It makes sense since the PLAN-KEY is already present in the REST API call, but it could work if designed for that.

This is how I was able to avoid the duplicated names when referencing JOB with similar names.

curl -u admin:admin -H 'Accept: application/json' \
-X GET <BAMBOO-SERVER_URL>/rest/api/latest/search/jobs/<PLAN-KEY> \
| jq -r '.searchResults[] | select(.searchEntity.key == "TESTGRADLE-TG-TES") | "Stage name: " + .searchEntity.stageName'

Please let me know if that is an option for you.

Please let me know if that is an option for you.

Unfortunately no, as the script I'm writing is not for me, and I don't have control over the keys consumers will be using. I'm going to wait BAM-20620


Thanks @Daniel Santos 

Maybe you don't need to identify the stage and can come with a different approach to solve your issue. I don't know why you need the stage name. If you share the problem you are trying to solve we may find a different solution.

If you think there is no other solution, then the only option is to wait for BAM-20620.


Suggest an answer

Log in or Sign up to answer

Atlassian Community Events