Hello Marcin,
I have created a global variable for demo purpose. The variable is called demovariable
I created a bash script as follows:
#!/bin/bash
echo ${bamboo.demovariable}
I am getting the error '${bamboo.demovariable}: bad substitution'
Am I doing anything wrong?
P.S. Just to divert your attention to this important fact, I am trying to access these variables in a bash script running on my local machine and not as Bamboo inline script

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

"bad substitution" is an error message from bash. The variables are not being substituted, so they are left in the script which then fails to execute (bash and sh can't handle the dot in variable names).
I've verified that variables will not be substituted in script files, only for inline scripts. That's probably the reason.
As a workaround, you can use variables in "script arguments" and "environment variables" in the task configuration, and then use the arguments or env vars in the script.
Cheers,
Marcin

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

Hello Marcin,
I did get the point wherein you mentioned why cannot the bash access the variable using the dot.
But I am unable to understand the workaround that you have mentioned. Can you please explain that in greater detail?

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

Hello Marcin,
Thanks for the prompt reply. I think we both are probably proceeding on different tasks
I shall explain the exact requirement:
I have bamboo configured on my machine. I have set some predefined global variables in Bamboo. I have a bash script running on my local machine performing some operations. Some results are being generated. I want to now updates these results into the global variables that are present in my bamboo automatically from my local bash script itself.
Can you tell me how should I be doing that?
Regards,
Hardik

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

And in the "Variables" tab of a plan, I set worldName to "foo". When bamboo runs, it outputs:

worldName was set to: foo

Note that in the script task itself, it correctly reads and interprets a bamboo.variable, but when you run in a sub-shell (say, calling/running an external shell script from the "script" task), you just have to translate it to bamboo_variable.

Also, sorry for the very late reponse.

EDIT: I only now read your last comment, which was basically, "can you modify the global variables set in Bamboo by running a script locally inside Bamboo?" The answer is probably "no" - a cursory scan through the REST API showed that you can change them on a per-instance case (if they're a queued plan), or trigger a build/deploy via the REST API overriding existing variables, however, I didn't see a way to actually set the "Global Variables" in Bamboo overall directly. Note that with some things, I've had to scrape HTML to figure out what's going on. Essentially, create a Selenium "test" that automatically clicks through various buttons and whatnot to post the relevant information. It's a terrible hack and highly fragile, and likely to break something if you're not careful.

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

This approach requires you to have the JIRA administrative rights. The main aim of this article is to help you achieve an organized, easy-to-maintain workflows in your JIRA instance thereby, reducin...