Bamboo variable replacement in batch file
Asked Answered
T

1

15

We're running Atlassian's Bamboo build server 4.1.2 on a Windows machine. I've created a batch file that is executed within a Task. The script is just referenced in a .bat file an not inline in the task. (e.g. createimage.bat)

Within the createimage.bat, I'd like to use Bamboo's PLAN variables. The usual variable syntax is not working, means not replaced. A line in the script could be for example:

goq-image-${bamboo.INTERNALVERSION}-SB${bamboo.buildNumber}

Any ideas?

Tim answered 30/8, 2012 at 12:33 Comment(1)
I found this article : answers.atlassian.com/questions/66109/…Tim
T
17

You are using the internal Bamboo variables syntax, but the Script Task passes those into the operating system's script environment and they need to be referenced with the respective syntax accordingly, e.g. (please note the underscores between terms):

  • Unix - goq-image-$bamboo_INTERNALVERSION-SB$bamboo_buildNumber
  • Windows - goq-image-%bamboo_INTERNALVERSION%-SB%bamboo_buildNumber%

Surprisingly, I'm unable to find an official reference for the Windows variation, there's only Using variables in bash right now:

Bamboo variables are exported as bash shell variables. All full stops (periods) are converted to underscores. For example, the variable bamboo.my.variable is $bamboo_my_variable in bash. This is related to File Script tasks (not Inline Script tasks).

However, I've figured the Windows syntax from Atlassian's documentation at some point, and tested and used it as documented in Bamboo Variable Substitution/Definition:

  • these variables are also available as environment variables in the Script Task for example, albeit named slightly different, e.g. $bamboo_custom_aws_cfn_stack_StringWithRegex (Unix) or %bamboo_custom_aws_cfn_stack_StringWithRegex% (Windows)
Tamarin answered 5/12, 2013 at 2:9 Comment(2)
I know this has been a while, so maybe things have changed. I tried %bamboo_buildNumber% and %bamboo.buildNumber% in a batch-file, but the result was an empty string.Bybee
@Bybee just tested my script in Bamboo now and it's working. In Bamboo your script should be %bamboo_buildNumber%, but to use this variable\parameter in your batch file you'd need to pass it through when you call the batch file FROM Bamboo. Bamboo syntax (if I understand correctly) is not applicable outside of the Bamboo scope/plan.Erupt

© 2022 - 2024 — McMap. All rights reserved.