Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Hi,

 

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 - https://stedolan.github.io/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

${bambooUrl}/rest/api/latest/search/jobs/${planKey}?searchTerm=${jobName}

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:

/rest/api/latest/search/jobs/PROJ-PLAN?searchTerm=JOB2

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

bamboo_buildKey=TESTGRADLE-TG-TES

- one with

bamboo_buildKey=TESTGRADLE-TG-TESG

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

TESTGRADLE-TG-TES

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
TAGS
Community showcase
Published in Bamboo

Bamboo 101 Video

G’day Community! As we gear up to introduce Bamboo Data Center to the world, we wanted to make sure that we shared a bit more about Bamboo, the product. Our team has put together an overview video ...

219 views 4 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you