Default or override in variable interpolation

Timothy Goff June 2, 2023

In my build plan I have a a variable injection step which sets a variable (`

bamboo.inject.DOCKER_IMAGE_PATH_MAIN`).  This variable is the path to a docker image generated in the build which will then be used as the execution environment for the subsequent deployment plan.
I am able to successfully reference that variable in the deployment spes:
 DockerConfiguration dockerConfiguration = new DockerConfiguration().image("${bamboo.inject.DOCKER_IMAGE_PATH_MAIN}");
and it is interpolated as expected.  However, if I attempt to deploy a release from a build which does not have this variable injected, the `${bamboo.inject.DOCKER_IMAGE_PATH_MAIN}` string is left as is and docker (understandably) complains it cant find that image.
In Bash, I could do something like
${bamboo.inject.DOCKER_IMAGE_PATH_MAIN:-bamboo.DOCKER_IMAGE_DEFAULT_PATH} 

to fall back to the value of DOCKER_IMAGE_DEFAULT_PATH if DOCKER_IMAGE_PATH_MAIN is not defined. 

I was wondering if there is a way to define this sort of logic in bamboo variable interpolation, or alternatively, if there was a way to set a value for an injected variable at deploy time.

Thanks

 

2 answers

0 votes
Marcin Gardias
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 28, 2023

You can define a variable with the same name at global, plan or Deployment Environment level.  If injected variable exist it will override, if not, it will resolve to the 'broader scope' variable.

0 votes
Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 4, 2023

Check @Marcin Gardias comment below.

Marcin Gardias
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 28, 2023

Actually, deployments do inherit variables from the build that created the release that is being deployed BUT: inject variable task has to be set to create variables in RESULT scope (in other words: not LOCAL)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events