fix: explicit after_script for telegram notification

This commit is contained in:
mahdi 2026-07-20 19:41:27 +03:30
parent 124944302a
commit 8b0be162d8
1 changed files with 8 additions and 17 deletions

View File

@ -2,19 +2,6 @@ stages:
- test - test
- deploy - deploy
# -----------------------------------------------------------------
# Global Notification Logic (Runs after every job execution)
# -----------------------------------------------------------------
.notify_template: &notify_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 # Stage 1: DevSecOps Vulnerability Scanning
# ----------------------------------------------------------------- # -----------------------------------------------------------------
@ -24,7 +11,6 @@ security_scan:
name: aquasec/trivy:0.49.1 name: aquasec/trivy:0.49.1
entrypoint: [""] entrypoint: [""]
script: script:
# Scan the application docker image for High and Critical vulnerabilities
- trivy image --severity HIGH,CRITICAL nginxdemos/hello:plain-text - trivy image --severity HIGH,CRITICAL nginxdemos/hello:plain-text
# ----------------------------------------------------------------- # -----------------------------------------------------------------
@ -36,6 +22,11 @@ deploy_application:
script: script:
- docker pull nginxdemos/hello:plain-text - docker pull nginxdemos/hello:plain-text
- docker compose -f ./stacks/hello-world/docker-compose.yml up -d - docker compose -f ./stacks/hello-world/docker-compose.yml up -d
# Added bonus: Re-running ansible safely in pipeline if configuration changes after_script:
# - echo "$ANSIBLE_VAULT_PASSWORD" > .vault_pass - echo "=== STARTING TELEGRAM NOTIFICATION ==="
# - ansible-playbook -i hosts.ini main.yml --vault-password-file .vault_pass - 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}"