Why use a manual approval step in the deploy code?
Manual approval in Jenkins provides a mechanism to ensure quality, security and compliance in software development and deployment processes.
Manual approval
- Add this stage to the pipeline
stage('Approval') {
steps {
timeout(time: 15, unit: "MINUTES") {
input message: 'Do you want to approve the deployment?', ok: 'Yes'
}
echo "Initiating deployment"
}
}
Telegram Notifications
To send notifications we need two things
First: HTTP_API of bot
Second: CHAT_ID
HTTP_API of bot
-
Create telegram bot
- BotFather in Telegram (@botfather)
- Send /newbot command
- Enter bot name and bot username
token-http-api
CHAT_ID
1. Go to @myidbot
2. Enter: /start -> /getid
3. Save your chat_ID
Creating Jenkins Global Credentials
- Manage Jenkins -> Credentials -> System -> Global credentials (unrestricted)
- Add Crediantials(CHAT_ID & TELEGRAM_API)
Configurig pipeline
_At the top of the pipeline
environment {
// Telegram configuration
TOKEN = credentials('telegram-api')
CHAT_ID = credentials('telegram_chatid')
}
Declare two variables which contain the tokens
post {
success {
script {
sh "curl -X POST -H 'Content-Type: application/json' -d '{\"chat_id\": \"${CHAT_ID}\", \"text\": \"${JOB_NAME}: #${BUILD_NUMBER}\n✅ Deploy succeeded! \", \"disable_notification\": false}' \"https://api.telegram.org/bot${TOKEN}/sendMessage\""
}
}
failure {
script {
sh "curl -X POST -H 'Content-Type: application/json' -d '{\"chat_id\": \"${CHAT_ID}\", \"text\": \"${JOB_NAME}: #${BUILD_NUMBER}\n❌Deploy failure!\", \"disable_notification\": false}' \"https://api.telegram.org/bot${TOKEN}/sendMessage\""
}
}
aborted {
script {
sh "curl -X POST -H 'Content-Type: application/json' -d '{\"chat_id\": \"${CHAT_ID}\", \"text\": \"${JOB_NAME}: #${BUILD_NUMBER}\n❌Deploy aborted!\", \"disable_notification\": false}' \"https://api.telegram.org/bot${TOKEN}/sendMessage\""
}
}
}
I hope helpful!!
Top comments (0)