77 lines
2.2 KiB
Groovy
77 lines
2.2 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
BOT_DIR = '/srv/fymious-tg-bot'
|
|
VENV_DIR = '/srv/fymious-tg-bot/.venv'
|
|
TELEGRAM_BOT_TOKEN = credentials('telegram-bot-token')
|
|
}
|
|
|
|
stages {
|
|
stage('Checkout') {
|
|
steps {
|
|
echo 'Pulling latest code...'
|
|
checkout scm
|
|
}
|
|
}
|
|
|
|
stage('Setup') {
|
|
steps {
|
|
echo 'Setting up virtual environment and dependencies...'
|
|
sh '''
|
|
# Create bot directory if it doesn't exist
|
|
mkdir -p ${BOT_DIR}
|
|
|
|
# Copy files to bot directory
|
|
cp -r * ${BOT_DIR}/
|
|
|
|
cd ${BOT_DIR}
|
|
|
|
# Create virtual environment if it doesn't exist
|
|
if [ ! -d "${VENV_DIR}" ]; then
|
|
python3 -m venv ${VENV_DIR}
|
|
fi
|
|
|
|
# Install/update dependencies
|
|
${VENV_DIR}/bin/pip install -r requirements.txt
|
|
'''
|
|
}
|
|
}
|
|
|
|
stage('Deploy') {
|
|
steps {
|
|
echo 'Restarting bot...'
|
|
sh '''
|
|
# Kill existing bot process
|
|
pkill -f "python.*main.py" || true
|
|
|
|
# Wait a moment
|
|
sleep 2
|
|
|
|
# Start bot in background
|
|
cd ${BOT_DIR}
|
|
nohup ${VENV_DIR}/bin/python main.py > ${BOT_DIR}/bot.log 2>&1 &
|
|
|
|
# Verify bot started
|
|
sleep 3
|
|
if pgrep -f "python.*main.py" > /dev/null; then
|
|
echo "Bot started successfully!"
|
|
else
|
|
echo "Failed to start bot. Check logs at ${BOT_DIR}/bot.log"
|
|
exit 1
|
|
fi
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
success {
|
|
echo 'Deployment successful!'
|
|
}
|
|
failure {
|
|
echo 'Deployment failed!'
|
|
}
|
|
}
|
|
}
|