How to use Bamboo plan variables in an inline script task?

Chris F picture Chris F · May 22, 2017 · Viewed 9.9k times · Source

When defining a Bamboo plan variable, the page has this.

For task configuration fields, use the syntax ${bamboo.myvariablename}. For inline scripts, variables are exposed as shell environment variables which can be accessed using the syntax $BAMBOO_MY_VARIABLE_NAME (Linux/Mac OS X) or %BAMBOO_MY_VARIABLE_NAME% (Windows).

However, that doesn't work in my Linux inline script. For example, I have the following defined a a plan variable

name: my_plan_var    value: some_string

My inline script is simply...

PLAN_VAR=$BAMBOO_MY_PLAN_VAR
echo "Plan var: $PLAN_VAR"

and I just get a blank string.

I've tried this

PLAN_VAR=${bamboo.my_plan_var}

But I get

${bamboo.my_plan_var}: bad substitution

on the log viewer window.

Any pointers?

Answer

ToAsT picture ToAsT · Jun 4, 2017

I tried the following and it works:

On the plan, I set my_plan_var to "it works" (w/o quotes)

In the inline script (don't forget the first line):

#/bin/sh

PLAN_VAR=$bamboo_my_plan_var
echo "testing: $PLAN_VAR"

And I got the expected result:

testing: it works