Using Bamboo variables in Katalon scripts

I have created a bamboo variable and i’m trying to access the bamboo variables inside katalon scripts. How it can be called inside katalon?

hello,
simplest way is to set them as global variables using

katalonc -g_XXX

more details in standard documentation here:

1 Like

bamboo exposes global variables (same for plan variables) in the execution environment (as bamboo_variable_name or bamboo.variable_name)
so either use the above solution to pass them as katalon global variabiles or use getenv straight in your code.
the first option is to be preferred, is more flexible (you override the values in the execution line) but you have to declare first the global variables in your project.
the second is more rigid, for debugging (execute the suite on local machine) you have to set them manually in your execution environment first, but does not depend on variables being declared in the project profiles.
see this quick guide on how to use getenv: https://www.tutorialspoint.com/java/lang/system_getenv_string.htm

2 Likes

in the old days when -g_xxx switch was not around i used script in listeners that set environment/variables for me
principle was - if there is an envitonment variable set - use that otherwise use value from profile - that allows me to switch between executions as i liked and deploy to CI/CD pipline:

import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.annotation.BeforeTestSuite
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.context.TestSuiteContext
import com.kms.katalon.core.util.KeywordUtil

import internal.GlobalVariable as GlobalVariable

class PrepareEnvVariables {
	/**
	 * Executes before every test suite starts.
	 * @param testSuiteContext: related information of the executed test suite.
	 */
	@BeforeTestSuite
	def prepareEnvVariables(TestSuiteContext testSuiteContext) {
		KeywordUtil.logInfo(testSuiteContext.getTestSuiteId())
		def gVars = ['systemPath','seleniumBoxToken_password','runOnBrowser','resultPath','testSuiteID','Time_Threshold', 'and_other_variables']
		gVars.each{
			if(System.getenv("${it}") != null){
				GlobalVariable."${it}" = System.getenv("${it}")
			}
		}
	}
}

can be also improved and get list of global variables from profile itself

1 Like

@Andrej_Podhajsky same idea was in my mind.
to make it more cool, you don’t need to use != null but you can use the ternary operator for assignment, since null is boolean false.
or even more cool, use the groovy Elvis operator so you don’t have to write getenv twice, see 5.4 here:
https://groovy-lang.org/operators.html#_elvis_operator

having this in mind one may write his own class, (your model is a good starting point), if the variable is not present in the env will get a default value.
that will make the script independent from global variables.