Skip to content

Instantly share code, notes, and snippets.

@arsalanses
Last active July 26, 2023 10:47
Show Gist options
  • Select an option

  • Save arsalanses/aae3e2fec4642cc7173aaef12f118c64 to your computer and use it in GitHub Desktop.

Select an option

Save arsalanses/aae3e2fec4642cc7173aaef12f118c64 to your computer and use it in GitHub Desktop.
Set Up GitLab Notifications in Telegram
#!/bin/bash
# You may want to change this
# Or make a secret variable
TELEGRAM_BOT_TOKEN=""
TELEGRAM_CHAT_ID=""
TIME="10"
URL="https://api.telegram.org/bot$${TELEGRAM_BOT_TOKEN}/sendMessage"
GITLAB_USER_NAME=$(echo $GITLAB_USER_NAME | sed 's/ /%20/g')
STATUS=$(echo $${1} | sed 's/ /%20/g')
TEXT="Deploy status: $${STATUS}%0A%0AProject:+$CI_PROJECT_NAME%0AURL:+$CI_PROJECT_URL/pipelines/$CI_PIPELINE_ID/%0ABranch:+$CI_COMMIT_REF_SLUG%0AUser:+$${GITLAB_USER_NAME}"
curl -s --max-time $${TIME} -d "chat_id=$${TELEGRAM_CHAT_ID}&disable_web_page_preview=1&text=$${TEXT}" $${URL} > /dev/null
# Step example on gitlab:
# notify_error:
# stage: notify
# script:
# - apk add curl
# - cp $notify ./notify.sh
# - sh notify.sh "fail message ❌ or success message ✅"
# - rm ./notify.sh
# when: on_failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment