version: 2.1
orbs:
katalon-studio: katalon/katalon-studio@23.0.11
slack: circleci/slack@4.12.0 # Include Slack Orb
workflows:
build:
jobs:
- katalon-studio/run:
version: "latest"
command_arguments: '-retry=0 -testSuitePath="Test Suites/I am on the website" -browserType="greg_lambdatest"'
post-steps:
- run:
name: Save Job ID
command: echo ${CIRCLE_WORKFLOW_JOB_ID} > /tmp/job_id.txt
- persist_to_workspace:
root: /tmp
paths:
- job_id.txt
- post_to_slack:
requires:
- katalon-studio/run
filters:
branches:
only: Dev_New # âś… Keep filters for branch control
jobs:
post_to_slack:
docker:
- image: cimg/base:stable
steps:
- attach_workspace:
at: /tmp
- run:
name: "Determine Job Status & Send Slack Notification"
command: |
# Read the job ID from the file and strip any unwanted characters
KATALON_JOB_ID=$(cat /tmp/job_id.txt | tr -d '[:space:]')
# Determine if the pipeline passed or failed
if [[ "$CIRCLE_JOB_STATUS" == "failed" ]]; then
STATUS="❌ *FAILED*"
else
STATUS="âś… *PASSED*"
fi
# Get the correct artifact URL dynamically
ARTIFACT_URL="https://output.circle-artifacts.com/output/job/${KATALON_JOB_ID}/artifacts/0/report/report.html"
# Fetch execution duration (start and end time)
EXECUTION_TIME=$(circleci-agent step timing | awk '/Total/{print $3}')
# Send the message to Slack
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\": \"${STATUS} - Test Report: <${ARTIFACT_URL}|Click here to view>\"}" \
$SLACK_WEBHOOK_URL
I use the above circle-yml to run 2 jobs. Right now the 2nd job post_to_slack
is working and send a message with a link to the report/report.html generated from the katalon-studio/run job.
I’ve been trying to add more context to this message though and am having issues with various things.
-
The post_to_slack is only working when katalon-studio/run passes, if it fails then post_to_slack does not execute. I want my post_to_slack message to send regardless of a Pass or Fail for the test job.
-
I want to add more details to the Slack message such as Execution Time, Git branch, and even username
Can anyone advise me on how I can improve my YML to support these?