Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bamboo

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?

like image 898
Chris F Avatar asked May 22 '17 20:05

Chris F


People also ask

How do I get bamboo variables in script?

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).

How do I access bamboo variables?

Plan variables can be accessed by using ${ bamboo. varName }. Plan variables can also be overridden at runtime when running a manual build. For more information, see Running a plan build manually.

How do I use bamboo task script?

Go to the Tasks configuration tab for the job (this will be the default job if creating a new plan). Select the name of the desired script task, or select Add task > Script if creating a new task. A description of the task, which is displayed in Bamboo. Check or clear to selectively run this task.

How do I set a global variable in bamboo?

To access the Global variables page:From the top navigation bar select > Build resources > Global variables. Add, update, or delete the global variables, as desired: Add a new variable once you have entered the key and value for it. Updates to existing rows will be saved as you move between cells in the table.


1 Answers

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

like image 68
ToAsT Avatar answered Sep 22 '22 15:09

ToAsT