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

Having problem to dynamically retrieve the bamboo variable value

Kexin Pei
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 6, 2023

Hello, I'm writing a script to utilize the bamboo variables. I have a echo line looks like: echo ${bamboo.dependency.parent.!parentsIndex!} 

The parentsIndex variable is a number here based on my personal requirement and it's ensured that this number won't exceed the max index of the parents that this build has. So ideally, I want this line to output the name of the parent which I request for. However, it outputs ${bamboo.dependency.parent.1}, instead of dynamically retrieving the bamboo variable name. How should I change the way to set and echo this line?

1 answer

1 vote
Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 6, 2023

Hello @Kexin Pei 

Welcome to the Atlassian Community!

In Bamboo, variable substitution happens before the build is started. If a variable needs to be replaced or created during the build, you need to use an Inject Variables Task that will consume a Java properties file on a key=value format.

So basically, you must create a properties text file, consume it through the Inject Variables task and use the new variable from the next task (or Stage).

Check this documentation for more information:

Sincerely,

Eduardo Alvarenga
Atlassian Support APAC

--please don't forget to Accept the answer if the reply is helpful-- 

Kexin Pei
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 6, 2023

Hello Eduardo, 

 

Thanks for the reply : ) ! I still have a problem about how to create the properties text file. So in my usage, I want to access to a bamboo variable looks like: bamboo.dependency.parent.<parentsIndex>. So parentsIndex will be the namespace that I want to inject before the script. But parentsIndex is a calculated number instead of a simple self-customized namespace. How should I define this namespace in the properties text file then? 

 

Thanks,

Kexin

Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 7, 2023

Hello @Kexin Pei

bamboo.dependency.parent.# variables are protected and you can't overwrite them.

You can declare a second variable based on that output and consume it instead:

Try this:

#!/bin/bash

# This is to simulate Bamboo - it will there already
bamboo_dependency_parent_0=PLAN-KEY

# Index you want -- change it to the position you want here or via script
parentsIndex=0

# Declare the variable you will consume using dynamic vars
declare bamboo_dependency_parent_name=bamboo_dependency_parent_${parentsIndex}

# Evaluate and consume it -- this will print "PLAN-KEY"
echo ${!bamboo_dependency_parent_name}

 

 

Cheers,

Eduardo Alvarenga
Atlassian Support APAC

--please don't forget to Accept the answer if the reply is helpful-- 

Like Steffen Opel _Utoolity_ likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events