Pass Global Variables to my GitLab-CI Pipeline

I am curious if anyone has figured out a way to pass Global Variables to be used within their CI/CD Pipeline.

  • Problem: I want to dynamically report to Katalon Test Ops the release version my test is running against
  • Idea:
    ** Create a test listener that automaically sets a global variable at the beginning of every test case with the correct release version based on the environment I am running against (I have already done this)
    ** Pass this global variable to my CI/CD pipeline so that results are reported against the correct release version. Example: katalonc.sh -runMode=console -browserType="Chrome" -statusDelay=15 -testSuiteCollectionPath="Test Suites/Full_Regression" -apiKey="$KATALON_API_KEY" -testOpsReleaseId={GLOBAL VARIABLE HERE} --config -webui.autoUpdateDrivers=true

I understand I am able to override Global variables from the command line, but I am trying to accomplish the inverse of this.

Possibly your CI/CI pipeline is a bash shell script, which execute the following command:

katalonc.sh -runMode=console -browserType="Chrome" ...

When you say a way to pass Global Variables to be used within their CI/CD Pipeline, you can think about 2 approaches.

1st approach

Let’s assume you can modify the shell script katalonc.sh itself. Then you would want to modify katalonc.sh so that it creates a shell variable $RELEASE_VERSION and updated with the information of which you want to inform your CI/CD pipeline. Then, when katalonc.sh finished, the CI/CD Pipeline (a bash script) can refer to that shell variable.

Here we are concerned about how 2 shell scripts (CI/CD pipeline and katalonc.sh) can communicate.

Here we are not concerned about how the value of RELEASE_VERSION is passed from your Katalon test to the shell script katalonc.sh.

2nd approach

Modify your Katalon Test (Test Listener or Test Case, whatever) to create a file <projectDir>/release_version.txt in which you write any information you want. For example,

releaseVersion = 1.2.3

Then, the CI/CD Pipeline (a bash script) can read and consume the <projectDir>/release_version.txt file soon after katalonc.sh finished. For example, the CI/CD script can do this:

cat $katalonProjectDir/release_version.txt

But, as you are aware, you can not change the katalonc.sh script, because it is the part of KRE itself. So #1 is not your option.

Therefore, I think the latter option is for you.

Thanks @kazurayam! Do you happen to have any examples of this in action?

Let me suppose your test has written the version info into a file version.txt

1.2.3

Please note that the content may possibly contain new line character (\n).

then your shell script can read the file, create a shell variable V, set the version info into the V.

// 1st katalonc.sh execution writes version.txt file 
katalonc.sh ...

V=`tr -d '\n' < version.txt`
echo $V

// 2nd katalonc.sh execution accepts $V
katalonc.sh ... testOpsReleaseId="$V" ...

The tr command trims the \n.

A bit more sophisticated case:

Your test write this into a file info.txt:

version=1.2.3
username=John Doe
password=ThisIsNotAPassword

You want your shell script read this, create a shell variable U with value ‘John Doe’.

The following shell script can do this.

U=`cat info.txt | awk -v key="username" '
    BEGIN {
        FS="="
    }
    { if ($1 == key) print $2; }
'`

Good-old awk command is your friend.