to dynamically pass runtime parameters from GitLab CI/CD to Katalon tests using command-line arguments and GlobalVariables:
1. Define Global Variables in Katalon
First, declare the variables you want to pass in your Katalon project:
- Go to Profiles > Default (or your active profile) and add variables like:
deviceName = "default_device"
osVersion = "default_os"
browserStackAppId = "default_id"
2. Pass Parameters via GitLab CI/CD Pipeline
In your .gitlab-ci.yml
, pass the values using Katalon’s -g_
syntax to override GlobalVariables:
stages:
- test
katalon_test:
stage: test
script:
- katalon-execute.sh
-projectPath="/path/to/your-project.prj"
-retry=0
-testSuitePath="Test Suites/Your_Test_Suite"
-executionProfile="default"
-browserType="Remote"
-g_deviceName="iPhone_12"
-g_osVersion="14.0"
-g_browserStackAppId="bs://123456abc"
-apiKey=$KATALON_API_KEY
3. Access Variables in Test Cases
Use the variables directly in your test scripts via GlobalVariable
:
// Example: Set Appium desired capabilities
@Keyword
def setupMobileDriver() {
String appId = GlobalVariable.browserStackAppId
String device = GlobalVariable.deviceName
String os = GlobalVariable.osVersion
Mobile.startApplication(appId, [
'deviceName' : device,
'platformVersion' : os,
'platformName' : 'iOS'
])
}
4. Handle Optional/Dynamic Values
For optional parameters, use defaults or conditionals to avoid NullPointerException
:
String appId = GlobalVariable.getProperty('browserStackAppId') ?: "default_id"
5. Secure Sensitive Data with GitLab Variables
For secrets (e.g., API keys), use GitLab’s CI/CD Variables (masked/env-protected):
- Navigate to GitLab Project > Settings > CI/CD > Variables.
- Add variables like
KATALON_API_KEY
, BROWSERSTACK_USER
, etc.
- Reference them in
.gitlab-ci.yml
:
script:
- katalon-execute.sh
...
-g_browserStackUser=$BROWSERSTACK_USER
-g_browserStackKey=$BROWSERSTACK_KEY
6. Use Custom Execution Profiles (Optional)
If you need environment-specific configurations:
- Create a profile (e.g.,
GitLab
) in Katalon Studio.
- Set variables in the profile, then reference it via
-executionProfile="GitLab"
.
7. Command-Line Syntax Notes
- Global Variables: Use
-g_<variableName>=<value>
.
- Test Case Variables: Use
-testCaseVars.<variableName>=<value>
.
- Example:
-g_env="staging" -testCaseVars.username="test_user"
8. Verify Execution
Check the GitLab job logs to confirm variables are passed:
[INFO] Global Variable: deviceName = iPhone_12
[INFO] Global Variable: osVersion = 14.0
References