Issue when trying to get overridden bamboo variables to a custom plugin

When I am trying to run “customized” plan with below build variable.

image

and when I am logging that variable inside of my custom plugin

code snippet:

 buildLogger.addBuildLogEntry(taskContext.getBuildContext().getVariableContext().
                getEffectiveVariables().get("shortPlanKey").getValue());

I get below logout put instead of overridden value. Am I doing it wrong?

log snippet:

simple 06-Nov-2019 15:19:56 ${bamboo.shortPlanKey}

please help!

If I read your screenshot correctly, you are overriding the shortPlanKey variable with the explicit value “${bamboo.shortPlanKey}”, i.e. you defined the name of the variable as it’s value - which is what you then get back during the build.
Try changing “${bamboo.shortPlanKey}” in that override definition to the actually desired override value (or do not override at all, if you want to keep the original definition).

Dear @hopel,

thanks for the reply. What I need is the value(which will be overridden by the bamboo itself) for the variable called shortPlanKey when the build is been built as follows.

${bamboo.shortPlanKey} → The short key of the current plan (without project part), e.g. MAIN
as described in bamboo variable documentation

currently,this string “${bamboo.shortPlanKey}” is coming for that variable even without overriding manually.
Meanwhile, is there a way to get bamboo build specific variables from TaskContext object which is used when building custom plugins for bamboo ?

Take a look at How do you access Bamboo build variables in a custom task plugin for various approaches.
If you try the one using an injected CustomVariableContext, be aware that the getVariableContexts(CommonContext commonContext) method is deprecated since Bamboo 5.9 - it should still work, but to be on the safe side, try the recommended alternatives via getVariableContexts() or VariableSubstitutor (by means of the getVariableSubstitutorFactory() method) instead.

1 Like