Katalon - ClickUp Automation in Jenkins

Katalon - ClickUp Automation in Jenkins

For CI/CD (Continuous Integration/Continuous Delivery) to be successful automation testers need to know when and where their test case failed quickly. Whenever the test run fails in CI/CD pipeline, testers should know it and in turn, can raise the issue. This in turn will lead to a quality product without compromising time.

This is where Katalon - ClickUp Integration can be useful. When a developer updates or changes the code, automated test cases are run to check whether the new build doesn't affect the functionality of the application or whether the application behaves properly. If any issue occurs in the run the tester should know where it has failed and in turn can raise the issue.

This can be achieved by integrating Katalon studio with a project management tool like ClickUp.

Prerequisites

  1. You need a ClickUp account with the necessary permissions to create tasks in a list. ClickUp has provided an API for making our custom integrations.

  2. (optional) We will need to integrate Jenkins (open-source automation server) with Katalon first. Integrate Jenkins on docker hosted in Ubuntu.

Jenkins provides us steps to run shell scripts in the project build section. Here we can use the curl command to hit the ClickUp API.

Katalon Jenkins ClickUp

After having the necessary tools installed, you can run your Katalon test suite from Jenkins by configuring your project parameters in the build step.

sudo su - jenkins
export DISPLAY=:99
docker run -t --rm -e DISPLAY_CONFIGURATION=1600x1200x24 -v "$(pwd)":/tmp/project katalonstudio/katalon:8.5.2 katalonc.sh -projectPath=/tmp/project -browserType="Firefox" -retry=0 -statusDelay=15 -testSuitePath="TEST_SUITE_PATH" -executionProfile="Your_exec_profile" -apikey="YOUR_API_KEY_OF_KRE" --config -webui.autoUpdateDrivers=true

Here the docker statement gives an exit code other than 0 if the test suite fails. For example, if the test cases in the test suite fail it gives a return code of 3. We can write a script like If the exit code is equal to 3 runs a script.

#!/bin/bash
sudo su - jenkins
export DISPLAY=:99
docker run -t --rm -e DISPLAY_CONFIGURATION=1600x1200x24 -v "$(pwd)":/tmp/project katalonstudio/katalon:8.5.2 katalonc.sh -runMode=console -projectPath=/tmp/project -browserType="Firefox" -retry=0 -statusDelay=15 -testSuitePath="YOUR_TEST_SUITE_PATH" -executionProfile="YOUR_EXEC_PROFILE_NAME" -apikey="YOUR_API_KEY_OF_KRE" --config -webui.autoUpdateDrivers=true
ret_code=$?
if [[ $ret_code -ne 2 && $ret_code -ne 0 ]]
then
bash /var/lib/jenkins/workspace/PROJECT_FOLDER/YOUR_SHELL_SCRIPT_LOCATION -CLICKUP_API_KEY="CLICKUP_API_KEY" -LIST_ID="LIST_ID_CLICKUP" -REPORT_FOLDER_PATH="/var/lib/jenkins/workspace/TEST_SUITE_REPORT_PATH" 
fi

In Katalon Studio

In Katalon studio you can create a folder to store your shell scripts and call them in Jenkins.

Katalon gives reports in *.csv format with the below-mentioned columns. We can use it to create tasks.

Suite/Test/Step Name, Browser, Description, Tag, Start time, End time, Duration, Status

If the status column has value fails we can create a task in ClickUp using the below script.

#!/bin/bash
#Parsing command line arguments
for var in "$@"
do
    if [[ $( echo "$var" | cut -d '=' -f 1 ) = "-LIST_ID" ]]
    then
    LIST_ID=$( echo "$var" | cut -d '=' -f 2 )
    fi
    if [[ $( echo "$var" | cut -d '=' -f 1 ) = "-REPORT_FOLDER_PATH" ]]
    then
    REPORT_FOLDER_PATH=($( echo "$var" | cut -d '=' -f 2 ))
    fi
    if [[ $( echo "$var" | cut -d '=' -f 1 ) = "-CLICKUP_API_KEY" ]]
    then
    CLICKUP_API_KEY=$( echo "$var" | cut -d '=' -f 2 )
    fi
done

We can create tasks in ClickUp if the status of the test case is failed.

MY_STATUS="FAILED"

start time - Converting today's date into a Unix timestamp

stimestamp=$(date +%s000)

due date of the task - Adding 2 days to the start time and converting it into a Unix timestamp

duetimestamp=$((stimestamp + 2*24*60*60*1000))

changing directory to report folder

cd "$REPORT_FOLDER_PATH"
pwd

Creating a task in ClickUp

NR=$'\r'
fail=0

while IFS="~" read -r Suite_Test_StepName Browser Description Tag Start_Time End_Time Duration Status
do
STAT=${Status%$NR}


if [[ ${Description} != null && ${Description} != '' && $MY_STATUS == $STAT ]]
then

curl -i -X POST \
  'https://api.clickup.com/api/v2/list/'"${LIST_ID}"'/task' \
  -H 'Content-Type: application/json'\
  -H 'Authorization: '"${CLICKUP_API_KEY}"\
  -d '{
    "name": "'"${Description}"'",
    "description": "'"${Suite_Test_StepName}"'",
    "assignees": [],
    "tags": ["automation"],
    "Status": "Open",
    "priority": 3,
    "due_date": "'${duetimestamp}'",
    "due_date_time": false,
    "time_estimate": 8640000,
    "start_date": "'${stimestamp}'",
    "start_date_time": false,
    "notify_all": false,
    "parent": null,
    "links_to": null,
    "check_required_custom_fields": true,
    "custom_fields": [
        ]
  }' 
  fi
  done < <(awk -F\" 'BEGIN{OFS=FS;} {for(i=1;i<=NF;i=i+2){gsub(/,/,"~",$i);} print $0;}' *.csv)

That's it, a task will be created if a test case fails.

Katalon-Clickup integration not only makes workflow smoother but also saves a lot of time. Have you tried implementing it? Let us know!

The code from this blog is available at this GitHub link