From 8b0be162d886bb95b6fc86d708b1b153b86acb0b Mon Sep 17 00:00:00 2001 From: mahdi Date: Mon, 20 Jul 2026 19:41:27 +0330 Subject: [PATCH] fix: explicit after_script for telegram notification --- .gitlab-ci.yml | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ed48e7c..db3b370 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,19 +2,6 @@ stages: - test - deploy -# ----------------------------------------------------------------- -# Global Notification Logic (Runs after every job execution) -# ----------------------------------------------------------------- -.notify_template: ¬ify_template - after_script: - - echo "Checking Telegram Variables..." - - echo "Chat ID is set to: ${TELEGRAM_CHAT_ID}" - - | - curl -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ - -d "chat_id=${TELEGRAM_CHAT_ID}" \ - -d "parse_mode=Markdown" \ - -d "text=Test notification from GitLab pipeline" - # ----------------------------------------------------------------- # Stage 1: DevSecOps Vulnerability Scanning # ----------------------------------------------------------------- @@ -24,7 +11,6 @@ security_scan: name: aquasec/trivy:0.49.1 entrypoint: [""] script: - # Scan the application docker image for High and Critical vulnerabilities - trivy image --severity HIGH,CRITICAL nginxdemos/hello:plain-text # ----------------------------------------------------------------- @@ -36,6 +22,11 @@ deploy_application: script: - docker pull nginxdemos/hello:plain-text - docker compose -f ./stacks/hello-world/docker-compose.yml up -d - # Added bonus: Re-running ansible safely in pipeline if configuration changes - # - echo "$ANSIBLE_VAULT_PASSWORD" > .vault_pass - # - ansible-playbook -i hosts.ini main.yml --vault-password-file .vault_pass \ No newline at end of file + after_script: + - echo "=== STARTING TELEGRAM NOTIFICATION ===" + - echo "Target Chat ID is: ${TELEGRAM_CHAT_ID}" + - | + curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ + -d "chat_id=${TELEGRAM_CHAT_ID}" \ + -d "parse_mode=Markdown" \ + -d "text=🚀 *Deployment Succeeded!*%0A*Project:* ${CI_PROJECT_NAME}%0A*Commit:* ${CI_COMMIT_TITLE}" \ No newline at end of file